Ejemplo n.º 1
0
        private void CreateCache(string name, long cacheMemoryLimitMegabytes, long physicalMemoryLimitPercentage, TimeSpan pollingInterval)
        {
            var nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("cacheMemoryLimitMegabytes", cacheMemoryLimitMegabytes.ToString());
            nameValueCollection.Add("physicalMemoryLimitPercentage", physicalMemoryLimitPercentage.ToString());
            nameValueCollection.Add("pollingInterval", pollingInterval.ToString());
            memoryCache_ = new EnumerableMemoryCache(name, nameValueCollection);
        }
Ejemplo n.º 2
0
        public void Clear()
        {
            lock (SyncRoot)
            {
                memoryCache_.Dispose();
                memoryCache_ = null;

                CreateCache(name_, cacheMemoryLimitMegabytes_, physicalMemoryLimitPercentage_, pollingInterval_);
            }
        }
Ejemplo n.º 3
0
        protected override void Dispose(bool disposing)
        {
            Log.Info(string.Format("'{0}:{1}' Dispose()", GetType().FullName, GetHashCode()));
            if (disposing)
            {
                cacheItemPolicy_.RemovedCallback = null;

                memoryCache_.Dispose();
                memoryCache_ = null;
            }
        }
Ejemplo n.º 4
0
 public void Remove(string key, string regionName = null)
 {
     lock (SyncRoot)
     {
         if (!Contains(EnumerableMemoryCache.BuildKey(key, regionName)))
         {
             return;
         }
         memoryCache_.Remove(EnumerableMemoryCache.BuildKey(key, regionName));
     }
 }
Ejemplo n.º 5
0
        public void AddRegion(string regionName, IEnumerable <KeyValuePair <string, object> > region, bool unlockIt = true)
        {
            lock (SyncRoot)
            {
                RemoveRegion(regionName);

                foreach (var item in region)
                {
                    memoryCache_.Add(new CacheItem(EnumerableMemoryCache.BuildKey(item.Key, null), new LockableValue(item.Value, locked: false)), cacheItemPolicy_);
                }
            }
        }
Ejemplo n.º 6
0
 public void Add(string key, object value, bool unLockit = true, string regionName = null)
 {
     lock (SyncRoot)
     {
         var item = memoryCache_.Get(EnumerableMemoryCache.BuildKey(key, regionName)) as LockableValue;
         if (item == null)
         {
             memoryCache_.Add(new CacheItem(EnumerableMemoryCache.BuildKey(key, regionName), new LockableValue(value, locked: false)), cacheItemPolicy_);
             return;
         }
         item.Value  = value;
         item.Locked = !unLockit && item.Locked;
     }
 }
Ejemplo n.º 7
0
 public object Get(string key, bool lockIt = false, string regionName = null)
 {
     lock (SyncRoot)
     {
         var value = memoryCache_.Get(EnumerableMemoryCache.BuildKey(key, regionName)) as LockableValue;
         if (value == null)
         {
             return(null);
         }
         if (value.Locked)
         {
             throw new ObjectLockedException(string.Format("Item with key '{0}' is locked", key));
         }
         if (lockIt)
         {
             Add(key, value.Value, unLockit: false, regionName: regionName);
         }
         return(value.Value);
     }
 }