Quantcast
Viewing latest article 16
Browse Latest Browse All 20

Updated Wiki: Introduction to ICacheManager

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.
publicclass ArticleService : IArticleService
{
    privatereadonly 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.
publicstatic T Get<T>(this ICacheManager cacheManager, string key, Func<T> acquire)

Viewing latest article 16
Browse Latest Browse All 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>