Esempio n. 1
0
        /// <summary>
        /// Fetches data and inserts it into cache
        /// </summary>
        public void FetchAndInsertData()
        {
            CacheItemContainer cacheItemContainer = ContinuousCacheAccessSynchronizationManager.GetCacheItemContainer(_CacheItemName);
            string             cacheKey           = cacheItemContainer.CacheKey + _IterationKey;

            ContinuousCacheAccessSynchronizationManager.SetIsFetchingDataFlag(cacheKey, true);

            lock (ContinuousCacheAccessSynchronizationManager.CacheItemNameLocks[cacheItemContainer.CacheItem.Name])
            {
                #region debug
#if DEBUG
                Trace.WriteLine(DebugConstants.DEBUG_PREFIX + "SEPARATE THREAD: Starting FetchAndInsertData at " + DateTime.UtcNow.ToString("HH:mm:ss.fff"));
#endif
                #endregion

                T item = default(T);

                try { item = _LoadObjectDelegate.Invoke(); }
                catch (Exception e) { throw new CachingException("An error occurred during the execution of the loadObject delegate. See the inner exception for further details.", e); }

                if (item != null)
                {
                    cacheItemContainer.LatestFetch = DateTime.UtcNow;

                    CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                    cacheItemPolicy.Priority           = cacheItemContainer.CacheItem.CacheItemPriority;
                    cacheItemPolicy.AbsoluteExpiration = cacheItemContainer.ActualExpiryDate;

                    SlimCacheManager._Cache.Set(
                        cacheKey
                        , item
                        , cacheItemPolicy);

                    #region debug
#if DEBUG
                    Trace.WriteLine(DebugConstants.DEBUG_PREFIX + "\n***\n*INPROCESS CACHE INSERT:\n*\t\t\tInserted new object into cache at " + cacheItemContainer.LatestFetch.ToString("HH:mm:ss.fff")
                                    + "\n*\t\t\tActual expiry date: " + cacheItemContainer.ActualExpiryDate.ToString("HH:mm:ss.fff")
                                    + "\n*\t\t\tInserted new stale key with expiry date: " + cacheItemContainer.SpecifiedExpiryDate.ToString("HH:mm:ss.fff")
                                    + "\n************************************************************************************************\n");
#endif
                    #endregion
                }
            }

            ContinuousCacheAccessSynchronizationManager.SetIsFetchingDataFlag(cacheKey, false);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates the save item instance.
 /// </summary>
 /// <param name="cacheItemName">Name of the cache item.</param>
 /// <returns></returns>
 private static CacheItemContainer CreateSaveItemInstance(string cacheItemName)
 {
     // we don't check whether the specified name acutally exists but just throw a key not found exception
     return(ContinuousCacheAccessSynchronizationManager.GetCacheItemContainer(cacheItemName));
 }