Introduction to ICacheManager

ICacheManager is a interface in namespace Aaron.Core.Caching; it use ObjectCache that's in namespace System.Runtime.Caching to cache any object. This action is useful for data loading, means it saves the page load time.

Easy to use, you just do as follows:
  • Declare a field with private scope; and then, dependents it in constructor.
public class ArticleService : IArticleService
{
    private readonly ICacheManager _cache;

    public ArticleService(ICacheManager cache)
    {
        _cache = cache;
    }
}
  • Use a method named Get to cache
    public IList<Article> GetAllArticles()
    {
        return _cache.Get("key_of_cache", () =>
        {
            // Write something here...
        });
    }
Get is a method in pointer of ICacheManager that include the following attributes:
  1. string key: it's a key to identify a value in ObjectCache.
  2. Func<T> acquire: it's a delegate to encapsulates a method and returns a T object.
public static T Get<T>(this ICacheManager cacheManager, string key, Func<T> acquire)
I hope this article helpful for you, thanks for the reference. In the next article, we shall discuss the CRUD with Aaron.

Last edited Oct 26, 2012 at 4:57 PM by khiemnd777, version 2

Comments

No comments yet.