コード例 #1
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static bool RefreshByCacheKey(string key)
 {
     if (!CacheLockbox.ContainsCacheEntry(key))
     {
         return(false);
     }
     ThreadPool.QueueUserWorkItem(delegate(object o) {
         Update(o.ToString());
     }, key);
     return(true);
 }
コード例 #2
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static bool Update(string key)
 {
     if (!CacheLockbox.ContainsCacheEntry(key))
     {
         return(false);
     }
     lock (CacheLockbox.GetInternalLock(key))
     {
         InternalCallback(key);
     }
     return(true);
 }
コード例 #3
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 internal static void ItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
 {
     if (reason == CacheItemRemovedReason.Expired)
     {
         CacheEntry cacheEntry = CacheLockbox.GetCacheEntry(key);
         if (cacheEntry.LastUse.Add(cacheEntry.SlidingExpiration) > DateTime.Now)
         {
             _cache.Insert(key, value, null, DateTime.Now.Add(TimeSpan.FromSeconds(30.0)), TimeSpan.Zero, CacheItemPriority.Low, null);
             ThreadPool.QueueUserWorkItem(delegate(object o) {
                 string _key = o.ToString();
                 lock (CacheLockbox.GetInternalLock(_key))
                 {
                     InternalCallback(_key);
                 }
             }, key);
         }
     }
 }
コード例 #4
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static void RefreshByPattern(string pattern)
 {
     ThreadPool.QueueUserWorkItem(delegate(object _pattern) {
         IEnumerator <string> enumerator = CacheLockbox.Keys.GetEnumerator();
         Regex regex = new Regex(_pattern.ToString(), RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
         while (enumerator.MoveNext())
         {
             string current = enumerator.Current;
             if (regex.IsMatch(current))
             {
                 lock (CacheLockbox.GetInternalLock(current))
                 {
                     InternalCallback(current);
                     continue;
                 }
             }
         }
     }, pattern);
 }
コード例 #5
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
        internal static object InternalCallback(string key)
        {
            CacheEntry cacheEntry = CacheLockbox.GetCacheEntry(key);

            if (cacheEntry == null)
            {
                return(null);
            }
            CacheLoaderDelegate cacheLoader = cacheEntry.CacheLoader;

            if (cacheLoader == null)
            {
                return(null);
            }
            object obj2 = null;

            try
            {
                obj2 = cacheLoader();
            }
            catch (Exception exception)
            {
                if (_cacheLoaderErrorDelegate != null)
                {
                    try
                    {
                        _cacheLoaderErrorDelegate(key, exception);
                    }
                    catch
                    {
                    }
                }
            }
            if (obj2 != null)
            {
                Insert(key, obj2, null, (int)cacheEntry.RefreshInterval.TotalSeconds, CacheItemPriority.Normal, new CacheItemRemovedCallback(TCache.ItemRemovedCallback));
                CacheLockbox.UpdateCacheEntry(key, DateTime.Now);
            }
            return(obj2);
        }
コード例 #6
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static object GetCacheEntryLock(string key, TimeSpan refreshInterval, TimeSpan slidingExpiration, CacheLoaderDelegate loaderDelegate)
 {
     return(CacheLockbox.GetLock(key, refreshInterval, slidingExpiration, loaderDelegate));
 }
コード例 #7
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static object GetCacheEntryLock(string key, int refreshIntervalSeconds, int slidingExpirationSeconds, CacheLoaderDelegate loaderDelegate)
 {
     return(CacheLockbox.GetLock(key, TimeSpan.FromSeconds((double)(refreshIntervalSeconds * Factor)), TimeSpan.FromSeconds((double)(slidingExpirationSeconds * Factor)), loaderDelegate));
 }
コード例 #8
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static object GetCacheEntryLock(string key)
 {
     return(CacheLockbox.GetLock(key));
 }
コード例 #9
0
ファイル: TCache.cs プロジェクト: wefasdfaew2/tngames
 public static bool ContainsCacheEntry(string key)
 {
     return(CacheLockbox.ContainsCacheEntry(key));
 }