Exemplo n.º 1
0
 public MemoryAdapter(CacheSettings cacheSettings)
 {
     CacheSettings = cacheSettings;
     _memoryCache = new MemoryCache(cacheSettings.Name);
     _expirationType = cacheSettings.ExpirationType;
     _minutesToExpire = cacheSettings.TimeToLive;
 }
Exemplo n.º 2
0
        public static CacheManager GetCacheManager(string name)
        {
            CacheSettings cacheSettings = new CacheSettings();

            cacheSettings.CacheType = CacheType.Memory;
            cacheSettings.ExpirationType = ExpirationType.Absolute;
            cacheSettings.Name = name;
            cacheSettings.TimeToLive = 3600;

            return GetCacheManager(cacheSettings);
        }
Exemplo n.º 3
0
        public static CacheManager GetCacheManager(CacheSettings cacheSettings)
        {
            CacheManager cache = null;

            switch (cacheSettings.CacheType)
            {
                case CacheType.Memory:
                    cache = GetInstance(cacheSettings, new MemoryAdapter(cacheSettings));
                    break;
                default:
                    cache = GetInstance(cacheSettings, new MemoryAdapter(cacheSettings));
                    break;
            }

            return cache;
        }
Exemplo n.º 4
0
        private static CacheManager GetInstance(CacheSettings cacheSettings, CacheManager newAdapter)
        {
            CacheManager instance = null;

            if (_caches.Count > 0)
                foreach (var cache in _caches)
                    if (cache.CacheSettings.Name.Equals(cacheSettings.Name))
                        instance = cache;

            if (instance == null)
            {
                instance = newAdapter;
                _caches.Add(newAdapter);
            }

            return instance;
        }