Esempio n. 1
0
        internal static object GetLock(string key, TimeSpan refreshInterval, TimeSpan slidingExpiration, CacheItemRemovedCallback cacehRemoved, NHashtable table)
        {
            HashCacheEntry entry = new HashCacheEntry();
            entry.RefreshInterval = refreshInterval;
            entry.SlidingExpiration = slidingExpiration;
            entry.LastUse = DateTime.Now;
            entry.CacheRemoved = cacehRemoved;
            entry.RefTable = table;
            CacheLockbox.Add(key, entry);

            return entry.Locker;
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the element with the specified key from the NHashtable
        /// </summary>
        /// <param name="key">The key of the element to remove</param>
        public void Remove(string key)
        {
            string cacheKey = CacheKey(key, _hashkey);

            CacheEntry entry = null;
            if (CacheLockbox.TryGetCacheEntry(cacheKey, out entry))
            {
                lock (CacheLockbox.GetLock(cacheKey))
                {
                    HashCacheEntry hashEntry = (HashCacheEntry)entry;
                    if (hashEntry.CacheRemoved != null)
                        hashEntry.CacheRemoved(key, base[cacheKey], CacheItemRemovedReason.Removed);
                    NCache.Remove(cacheKey);
                }
            }
            base.Remove(cacheKey);
        }
Esempio n. 3
0
        /// <summary>
        /// Callback method called when a object is removed for the ASP.NET cache.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="reason">The reason an item was removed from the ASP.NET cache</param>
        internal static void ItemRemovedCallback(string cacheKey, object value, CacheItemRemovedReason reason)
        {
            if (reason == CacheItemRemovedReason.Expired)
            {
                int num = cacheKey.IndexOf('-');
                string key = cacheKey.Substring(0, num);

                CacheEntry cacheEntry = null;
                if (CacheLockbox.TryGetCacheEntry(cacheKey, out cacheEntry))
                {
                    if (cacheEntry.LastUse.Add(cacheEntry.SlidingExpiration) > DateTime.Now) {
                        NCache.cache_.Insert(cacheKey, value, null, DateTime.Now.Add(TimeSpan.FromSeconds(30.0)), TimeSpan.Zero, CacheItemPriority.Low, null);
                        ThreadPool.QueueUserWorkItem(delegate(object o)
                        {
                            string k = o.ToString();
                            lock (CacheLockbox.GetInternalLock(k)) {
                                InternalCallback(k);
                            }
                        }, cacheKey);
                    }
                    else {
                        lock (CacheLockbox.GetLock(cacheKey))
                        {
                            HashCacheEntry hashEntry = (HashCacheEntry)cacheEntry;
                            if (hashEntry.CacheRemoved != null)
                                hashEntry.CacheRemoved(key, value, reason);
                            
                            NHashtable table = hashEntry.RefTable;
                            if (table != null)
                                table.Remove(cacheKey);
                        }
                        CacheLockbox.Remove(cacheKey);
                    }
                }
            }
        }