Ejemplo n.º 1
0
        public static T Get <T>(string cacheKey, Func <T> getData, TimeSpan expiration, bool loadFromCache = true) where T : class
        {
            // Modify the key
            cacheKey = ModifyKey(cacheKey);

            T data = null;

            if (loadFromCache && Enabled)
            {
                // Get the data
                data = CacheChannel.Get <T>(cacheKey);
            }

            if (data == null)
            {
                // Get data using the given function
                data = getData();
            }

            // Check for the data
            if (data != null)
            {
                // Add the data to cache
                Add(cacheKey, data, expiration);
            }
            return(data);
        }
Ejemplo n.º 2
0
        private static void AddCacheKeyToCollection(string cacheKey)
        {
            // Get current cache keys
            List <string> allCacheKeys = CacheChannel.Get <List <string> >("AllCacheKeys");

            if (allCacheKeys == null)
            {
                allCacheKeys = new List <string>();
            }

            // Check the key existence
            var key = ModifyKey(cacheKey);

            //if (key.Length > 150)
            //{
            //    key = SecurityService.Encrypt(key, EncryptorType.MD5Encryption);
            //}

            if (!allCacheKeys.Contains(key))
            {
                allCacheKeys.Add(key);
                CacheChannel.Set("AllCacheKeys", allCacheKeys);
            }
        }
Ejemplo n.º 3
0
 public static List <string> GetAllCacheKeys()
 {
     return(CacheChannel.Get <List <string> >("AllCacheKeys"));
 }