Exemplo n.º 1
0
        /// <summary>
        /// Caches the object of T.
        /// If the object is in the cache then it will return that object
        /// or else it will insert <see cref="addToCache"/> to the cache.
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="addToCache">This will run if the object is not in the cache.</param>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="cacheDurationInSeconds">The cache duration in seconds.</param>
        /// <param name="priority">The priority.</param>
        /// <returns>The object from the cache.</returns>
        public static T CacheObject <T>(AddToCacheAction <T> addToCache, string cacheKey, int cacheDurationInSeconds, CacheItemPriority priority)
        {
            CacheManager <string, T> cacheManager = CacheManager <string, T> .GetInstance();

            T cachedObject = cacheManager[cacheKey];

            if (cachedObject == null)
            {
                cachedObject = addToCache();
                if (cachedObject != null)
                {
                    cacheManager.Insert(cacheKey, cachedObject, cacheDurationInSeconds, priority);
                }
            }
            return(cachedObject);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Caches the object of T.
 /// If the object is in the cache then it will return that object
 /// or else it will insert <see cref="addToCache"/> to the cache.
 /// </summary>
 /// <typeparam name="T">The type of object.</typeparam>
 /// <param name="addToCache">This will run if the object is not in the cache.</param>
 /// <param name="cacheKey">The cache key.</param>
 /// <param name="cacheDurationInSeconds">The cache duration in seconds.</param>
 /// <returns>The object from the cache.</returns>
 public static T CacheObject <T>(AddToCacheAction <T> addToCache, string cacheKey, int cacheDurationInSeconds)
 {
     return(CacheObject <T>(addToCache, cacheKey, cacheDurationInSeconds, CacheItemPriority.Normal));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Caches the object of T.
 /// If the object is in the cache then it will return that object
 /// or else it will insert <see cref="addToCache"/> to the cache.
 /// </summary>
 /// <typeparam name="T">The type of object.</typeparam>
 /// <param name="addToCache">This will run if the object is not in the cache.</param>
 /// <param name="cacheKey">The cache key.</param>
 /// <returns>The object from the cache.</returns>
 public static T CacheObject <T>(AddToCacheAction <T> addToCache, string cacheKey)
 {
     return(CacheObject <T>(addToCache, cacheKey, CacheLength.GetDefaultCacheTime));
 }