Ejemplo n.º 1
0
 public RefreshableCache
 (
     string cacheKey
     , uint refreshIntervalInSeconds
     , Func <TData> onRefreshingCacheDataProcessFunc
     , bool needTryProcess   = true
     , bool reThrowException = false
     , Func <Exception, Exception, string, bool> onCaughtExceptionProcessFunc = null
     , Action <bool, Exception, Exception, string> onFinallyProcessAction     = null
 )
 {
     CacheKey          = cacheKey.Trim().ToLower();
     _cachedData       = onRefreshingCacheDataProcessFunc();
     LastRefreshedTime = DateTime.Now;
     var cacheItemEntryRemovedNotifier
         = new CacheItemEntryRemovedNotifier
           (
               CacheKey
               , refreshIntervalInSeconds
               , (x) =>
     {
         TData refreshedData = default(TData);
         if
         (
             TryGetRefreshedCacheData
             (
                 onRefreshingCacheDataProcessFunc
                 , out refreshedData
                 , needTryProcess
                 , reThrowException
                 , onCaughtExceptionProcessFunc
                 , onFinallyProcessAction
             )
         )
         {
             _cachedData       = refreshedData;
             LastRefreshedTime = DateTime.Now;
         }
         return(true);
     }
           );
 }
        static void x_CacheItemEntryRemoved(CacheItemEntryRemovedNotifier sender, CacheEntryRemovedReason reason)
        {

            sender.ExpireSeconds = 10;
        }