Пример #1
0
        public string UnBindCacheRegion(string groundId)
        {
            string message = string.Empty;

            groundId = groundId.Trim();
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CacheRegion entity = dbContext.CacheRegions.FirstOrDefault(x => x.ChildAreaId == groundId);
                    if (entity == null)
                    {
                        message = "该地堆不可用!";
                    }
                    else
                    {
                        entity.Material_A = null;
                        entity.Material_B = null;
                        entity.Material_C = null;
                        dbContext.SaveChanges();
                        message = "解绑成功!";
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(message);
        }
Пример #2
0
        /// <summary>
        /// Handles a cache event for the <see cref="TcmCDService.CacheClient.RMI.CacheConnector" />
        /// </summary>
        /// <param name="region">Cache region</param>
        /// <param name="key">Cache key</param>
        /// <param name="eventType">Cache event type</param>
        void com.tridion.tcmcdservice.rmi.CacheChannelEventListener.onCacheEvent(String region, String key, int eventType)
        {
            CacheRegion    cacheRegion    = CacheRegionExtensions.ToCacheRegion(region);
            CacheEventType cacheEventType = (CacheEventType)eventType;

            base.OnCacheEvent(cacheRegion, key, cacheEventType);
        }
Пример #3
0
        public void CacheItemRange(int startIndex, int endIndex)
        {
            CacheRegion         region        = new CacheRegion(startIndex, endIndex);
            IList <CacheRegion> regionsToLoad = FindUncachedRegions(region);

            if (regionsToLoad != null)
            {
                // Since we're loading anyway pad the region a bit to load a decent minimum number of
                // items at a time, avoiding many small load requests. This is ONLY done if a load
                // is required in the first place.

                if (regionsToLoad.Count == 1)
                {
                    regionsToLoad = FindUncachedRegions(PadRegionToLoad(regionsToLoad[0]));
                }

                foreach (CacheRegion regionToLoad in regionsToLoad)
                {
                    Stopwatch watch = Stopwatch.StartNew();
                    m_loadRange(regionToLoad.StartIndex, regionToLoad.EndIndex);
                    Debug.WriteLine(string.Format("Loaded {0} in {1} ms.", regionToLoad, watch.ElapsedMilliseconds));
                    AddCachedRegion(regionToLoad);
                }
            }

            m_lastRequestedStartIndex = startIndex;
            m_minBatchToLoad          = Math.Max(m_minBatchToLoad, region.Size); // Next time load at least this many.
        }
Пример #4
0
 public static bool Remove(
     string key,
     CacheRegion region
     )
 {
     return(CacheManager.Remove(key, region.ToString()));
 }
Пример #5
0
 /// <summary>
 /// Trigger a CacheEvent for the <see cref="P:region" />, <see cref="P:key" /> and <see cref="P:eventType" />
 /// </summary>
 /// <param name="region"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param>
 /// <param name="key">Cache item key</param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param>
 protected void OnCacheEvent(CacheRegion region, String key, CacheEventType eventType)
 {
     if (CacheEvent != null)
     {
         CacheEvent(null, new CacheEventArgs(region, key, eventType));
     }
 }
Пример #6
0
        public static void InvalidateCache(CacheRegion? cacheRegion)
        {
            var requestProcessor = ServiceLocator.GetInstance<IRequestProcessor>();
            var request = new UpdateCacheStateRequest(cacheRegion);

            requestProcessor.Process(request);
        }
Пример #7
0
        public T Get <T>(string key, CacheRegion region) where T : class
        {
            object cachedObj;
            var    cachedItem = _dictionary.TryGetValue(key, out cachedObj) == true ? cachedObj as T : null;

            return(cachedItem);
        }
Пример #8
0
        public void ExpiredGlobalRegionTokenRemovesAll()
        {
            //Arrange
            var cache  = GetPlatformMemoryCache();
            var key1   = "myKey1";
            var key2   = "myKey2";
            var value1 = new object();
            var value2 = new object();

            var token1 = CacheRegion.CreateChangeTokenForKey(key1);
            var token2 = CacheRegion2.CreateChangeTokenForKey(key2);

            cache.Set(key1, value1, token1);
            cache.Set(key2, value2, token2);

            //Act
            GlobalCacheRegion.ExpireRegion();

            //Assertion
            var result = cache.Get(key1);

            Assert.Null(result);
            result = cache.Get(key2);
            Assert.Null(result);
        }
Пример #9
0
        private void AddCachedRegion(CacheRegion region)
        {
            int index = m_cacheRegions.BinarySearch(region);

            Debug.Assert(index < 0, "Region to be added already found in the list.");

            index = ~index;

            // Merge with the previous cached region, if adjacent.

            if (index > 0 && m_cacheRegions[index - 1].EndIndex >= region.StartIndex - 1)
            {
                region = new CacheRegion(m_cacheRegions[--index].StartIndex, region.EndIndex);
                m_cacheRegions.RemoveAt(index);
            }

            // Merge with the next cached region, if adjacent.

            if (index < m_cacheRegions.Count && m_cacheRegions[index].StartIndex <= region.EndIndex + 1)
            {
                region = new CacheRegion(region.StartIndex, m_cacheRegions[index].EndIndex);
                m_cacheRegions.RemoveAt(index);
            }

            m_cacheRegions.Insert(index, region);
        }
Пример #10
0
        /// <summary>
        /// Processes a cache event and trigger the dependent dependencies
        /// </summary>
        /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param>
        /// <param name="cacheEventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param>
        /// <param name="key">Cache item key</param>
        public static void ProcessCacheEvent(CacheRegion cacheRegion, CacheEventType cacheEventType, String key)
        {
            Logger.Debug("Processing cache event: region \"{0}\", key \"{1}\", type \"{2}\".", cacheRegion, key, cacheEventType);

            foreach (TridionDependency dependency in mDependencies)
            {
                if (dependency.CacheRegion.HasFlag(cacheRegion))
                {
                    Logger.Debug("\tDependency: {0}", dependency);
                    Logger.Debug("\tComparison: {0} vs {1}", dependency.Key, key);

                    switch (cacheEventType)
                    {
                    // Instruction to flush all entries from a CacheRegion
                    case CacheEventType.Flush:
                        dependency.TriggerDependency();
                        break;

                    // Instruction to invalidate a specific entry from a CacheRegion
                    case CacheEventType.Invalidate:
                        if (key.StartsWith(dependency.Key, StringComparison.OrdinalIgnoreCase))
                        {
                            dependency.TriggerDependency();
                        }
                        break;
                    }
                }
            }
        }
Пример #11
0
 public ContainsResult <T> Contains <T>(string key, CacheRegion region) where T : class
 {
     return(new ContainsResult <T>
     {
         CachedObj = null,
         Exists = false
     });
 }
Пример #12
0
        internal static void Remove(this ICacheService cacheService, CacheRegion region)
        {
            if (cacheService == null)
            {
                throw new ArgumentNullException(nameof(cacheService));
            }

            cacheService.RemoveRegion(region.ToString());
        }
        public bool Remove(string key, CacheRegion region)
        {
            // In case of CAS (optimistic concurrency is set)
            // var loaded = bucket.GetDocument<dynamic>("document_id");
            // var removed = bucket.Remove(loaded);

            var result = bucket.RemoveAsync(key).Result;

            return(result.Success);
        }
Пример #14
0
        public bool Remove(string key, CacheRegion region)
        {
            if (!Contains(key, region))
            {
                return(false);
            }

            _dictionary.Remove(key);
            return(true);
        }
Пример #15
0
        /// <summary>
        /// Convert a <see cref="T:TcmCDService.CacheTypes.CacheRegion" /> value to a <see cref="T:System.String" />
        /// </summary>
        /// <param name="value"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
        /// <returns>Cache region as <see cref="T:System.String" /></returns>
        public static String FromCacheRegion(CacheRegion value)
        {
            String result;

            if (mReverse.TryGetValue(value, out result))
            {
                return(result);
            }

            return(null);
        }
Пример #16
0
        public ContainsResult <T> Contains <T>(string key, CacheRegion region) where T : class
        {
            var containsResult = new ContainsResult <T>();

            containsResult.Exists = Contains(key, region);
            if (containsResult.Exists)
            {
                containsResult.CachedObj = Get <T>(key, region);
            }

            return(containsResult);
        }
Пример #17
0
 // 15 phút
 public static T GetOrSet <T>(string key, CacheRegion region, System.Func <T> valueFactory, TimeoutMinutes timeoutMinutes = TimeoutMinutes.m15)
 {
     try
     {
         if (!CacheManager.Exists(key, region.ToString()))
         {
             var item = new CacheItem <object>(key, region.ToString(), valueFactory(), ExpirationMode.Absolute, TimeSpan.FromMinutes((int)timeoutMinutes));
             CacheManager.Add(item);
         }
     }
     catch (Exception ex)
     {
         return(default(T));
     }
     return(CacheManager.Get <T>(key, region.ToString()));
 }
        public T Get <T>(string key, CacheRegion region) where T : class
        {
            // Was advised by Couchbase vendor to use ASYNC api in synchronous manor vs using the synchronous call
            // Said it was more optimized. Just so you know.
            var bytesBackOut = bucket.GetAsync <byte[]>(key).Result.Value;

            if (bytesBackOut == null)
            {
                return(null);
            }
            using (var stream = new MemoryStream(bytesBackOut))
            {
                var retrievedObject = (T)formatter.Deserialize(stream);
                return(retrievedObject);
            }
        }
 public void Save(string key, object toSave, CacheRegion region, TimeSpan expiration)
 {
     // Test if object is serializable first
     try
     {
         using (MemoryStream mem = new MemoryStream())
         {
             formatter.Serialize(mem, toSave);
             bucket.InsertAsync <byte[]>(key, mem.ToArray(), expiration);
         }
     }
     catch (Exception ex)
     {
         // Object is not serializable
         return;
     }
 }
Пример #20
0
        private CacheRegion PadRegionToLoad(CacheRegion region)
        {
            if (region.Size < m_minBatchToLoad)
            {
                // Pad the region with more indexes in the scroll direction up to the minimum batch size.

                if (region.StartIndex > m_lastRequestedStartIndex)
                {
                    region = new CacheRegion(
                        region.StartIndex, Math.Min(region.StartIndex + m_minBatchToLoad, Count) - 1);
                }
                else
                {
                    region = new CacheRegion(
                        Math.Max(region.EndIndex - m_minBatchToLoad + 1, 0), region.EndIndex);
                }
            }

            return(region);
        }
Пример #21
0
        public void ExpiredItemTokenRemovesItem()
        {
            //Arrange
            var cache = GetPlatformMemoryCache();
            var key   = "myKey";
            var value = new object();

            //Act
            var expirationToken = CacheRegion.CreateChangeTokenForKey(key);

            //Arrange
            var result = cache.Set(key, value, expirationToken);

            //Act
            Assert.Same(value, result);
            CacheRegion.ExpireTokenForKey(key);

            //Assertion
            result = cache.Get(key);
            Assert.Null(result);
        }
        public ContainsResult <T> Contains <T>(string key, CacheRegion region) where T : class
        {
            var containsResult = new ContainsResult <T>();

            try
            {
                var retrievedObject = Get <T>(key, region);

                containsResult.CachedObj = retrievedObject;
                containsResult.Exists    = containsResult.CachedObj != null;
            }
            catch (Exception ex)
            {
                // Try to remove key just in case its corrupt
                Remove(key, region);

                containsResult.Exists    = false;
                containsResult.CachedObj = null;
            }
            return(containsResult);
        }
Пример #23
0
        public string BindCacheRegion(string groundId, string materialId1, string materialId2, string materialId3)
        {
            string message = string.Empty;

            try
            {
                materialId1 = materialId1.Trim();
                materialId2 = materialId2.Trim();
                materialId3 = materialId3.Trim();
                groundId    = groundId.Trim();
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CacheRegion entity = dbContext.CacheRegions.FirstOrDefault(x => x.ChildAreaId == groundId);
                    if (entity == null)
                    {
                        message = "该地堆不存在!";
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(entity.Material_A) && string.IsNullOrEmpty(entity.Material_B) && string.IsNullOrEmpty(entity.Material_C))
                        {
                            entity.Material_A = materialId1;
                            entity.Material_B = materialId2;
                            entity.Material_C = materialId3;
                            dbContext.SaveChanges();
                            message = "绑定成功!";
                        }
                        else
                        {
                            message = "该地堆已经绑定小车";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(message);
        }
Пример #24
0
 public bool Contains(string key, CacheRegion region)
 {
     if (_dictionary.ContainsKey(key))
     {
         var cachedItem = _dictionary[key];
         // Check for expiration
         System.Reflection.PropertyInfo pi = cachedItem.GetType().GetProperty(nameof(CachedObjectResponseContainer <object> .CacheMetadata));
         if (pi != null)
         {
             CachedObjectMetadata metaData = (CachedObjectMetadata)(pi.GetValue(cachedItem, null));
             if (metaData != null && metaData.ExpirationDate <= DateTime.Now)
             {
                 return(false);
             }
         }
         else
         {
             // We are unable to evaluate expiration date, so we will always do live call.
             return(false);
         }
         return(cachedItem != null);
     }
     return(false);
 }
Пример #25
0
        public void CreateChangeTokenReturnsCompositeToken()
        {
            //Act
            var token = CacheRegion.CreateChangeTokenForKey("key");

            //Assertion
            Assert.IsType <CompositeChangeToken>(token);
            //Tokens for item, region and global
            Assert.Equal(3, ((CompositeChangeToken)token).ChangeTokens.Count);
            Assert.All(((CompositeChangeToken)token).ChangeTokens, x => Assert.IsType <LazyCancellationChangeToken>(x));

            //Act
            token = CacheRegion.CreateChangeToken();
            //Assertion
            Assert.IsType <CompositeChangeToken>(token);
            //Tokens for item, region and global
            Assert.Equal(2, ((CompositeChangeToken)token).ChangeTokens.Count);
            Assert.All(((CompositeChangeToken)token).ChangeTokens, x => Assert.IsType <LazyCancellationChangeToken>(x));

            //Act
            token = GlobalCacheRegion.CreateChangeToken();
            //Assertion
            Assert.IsType <LazyCancellationChangeToken>(token);
        }
Пример #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessCache"/> class.
 /// </summary>
 /// <param name="cacheRegion">Cache region.</param>
 /// <param name="cacheKeyPrefix">The cache key prefix.</param>
 /// <param name="disableForAdminUsers">Disable cache for admin users.</param>
 /// <param name="disableForStaffUsers">Disable cache for staff users</param>
 /// <param name="disableForPageEditors">Disable cache for page editors.</param>
 /// <param name="forceCache">Force the enabling of the cache for the current user.</param>
 public BusinessCache(CacheRegion cacheRegion, string cacheKeyPrefix, bool disableForAdminUsers, bool disableForStaffUsers, bool disableForPageEditors, bool forceCache)
 {
     _cache = GetCacheForRegion(cacheRegion);
     _keyPrefix = cacheKeyPrefix;
     _isCacheDisabledForCurrentUser = IsCacheDisabledForCurrentUser(disableForAdminUsers, disableForStaffUsers, disableForPageEditors, forceCache);
     _defaultCacheTime = new TimeSpan(0, 0, CacheSeconds.Small); // default to 30 seconds.
 }
Пример #27
0
 public UpdateCacheStateRequest(CacheRegion? cacheRegion)
 {
     Region = cacheRegion;
 }
Пример #28
0
 /// <summary> 
 /// Initializes a new instance of the BusinessCache class. 
 /// </summary>  
 /// <param name="cacheRegion">Cache region.</param>
 public BusinessCache(CacheRegion cacheRegion)
     : this(cacheRegion, DefaultKeyPrefix, true, false, true, false)
 {
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessCache"/> class.
 /// </summary>
 /// <param name="cacheRegion">Cache region.</param>
 /// <param name="cacheKeyPrefix">The cache key prefix.</param>
 /// <param name="disableForAdminUsers">Disable cache for admin users.</param>
 /// <param name="disableForStaffUsers">Disable cache for staff users</param>
 /// <param name="disableForPageEditors">Disable cache for page editors.</param>
 public BusinessCache(CacheRegion cacheRegion, string cacheKeyPrefix, bool disableForAdminUsers, bool disableForStaffUsers, bool disableForPageEditors)
     : this(cacheRegion, cacheKeyPrefix, disableForAdminUsers, disableForStaffUsers, disableForPageEditors, false)
 {
 }
Пример #30
0
        public void CancelTokenForKeyOnTokenCancelledCallCounts(bool propagate, int callbackCount)
        {
            //Arrange
            var registeryCallbackInvokedCount = 0;

            CancellableCacheRegion.OnTokenCancelled = args =>
            {
                Interlocked.Increment(ref registeryCallbackInvokedCount);
            };

            var cache  = GetPlatformMemoryCache();
            var key    = "myKey";
            var value1 = new object();
            var value2 = new object();

            var key1   = CacheRegion.GenerateRegionTokenKey(key);
            var token1 = CacheRegion.CreateChangeTokenForKey(key);
            var key2   = CacheRegion2.GenerateRegionTokenKey(key);
            var token2 = CacheRegion2.CreateChangeTokenForKey(key);

            //Act
            cache.Set(key1, value1, token1);
            cache.Set(key2, value2, token2);

            //Assertion
            var result = cache.Get(key1);

            Assert.Same(value1, result);
            result = cache.Get(key2);
            Assert.Same(value2, result);

            //Act
            CancellableCacheRegion.CancelForKey(key1, propagate);

            //Assertion
            result = cache.Get(key1);
            Assert.Null(result);
            result = cache.Get(key2);
            Assert.Same(value2, result);


            //Act
            CancellableCacheRegion.CancelForKey(key2, propagate);

            //Assertion
            result = cache.Get(key2);
            Assert.Null(result);

            //Arrange
            token1 = CacheRegion.CreateChangeTokenForKey(key);
            token2 = CacheRegion2.CreateChangeTokenForKey(key);
            cache.Set(key1, value1, token1);
            cache.Set(key2, value2, token2);

            //Act
            //cancel region
            CancellableCacheRegion.CancelForKey(CacheRegion.GenerateRegionTokenKey(), propagate);
            //Assertion
            result = cache.Get(key1);
            Assert.Null(result);
            result = cache.Get(key2);
            Assert.Same(value2, result);

            //Arrange
            token1 = CacheRegion.CreateChangeTokenForKey(key);
            token2 = CacheRegion2.CreateChangeTokenForKey(key);
            cache.Set(key1, value1, token1);
            cache.Set(key2, value2, token2);

            //Act
            //cancel global region
            CancellableCacheRegion.CancelForKey(GlobalCacheRegion.GenerateRegionTokenKey(), propagate);
            result = cache.Get(key1);
            Assert.Null(result);
            result = cache.Get(key2);
            Assert.Null(result);

            //Callback mustn't call
            Assert.Equal(callbackCount, registeryCallbackInvokedCount);
        }
Пример #31
0
 public void Save(string key, object toSave, CacheRegion region)
 {
     // non specified timeout is hardcoded for 24 hours.
     Save(key, toSave, region, CachePolicies.Default);
 }
Пример #32
0
 public static void InvalidateCache(CacheRegion cacheRegion)
 {
     MEDSEEK.eHealth.ServiceLayer.Business.Caching.CacheStateManager.InvalidateCache(cacheRegion);
 }
Пример #33
0
 public static BusinessCache GetCache(CacheRegion cacheRegion)
 {
     return GetCache(cacheRegion, true, false, true);
 }
Пример #34
0
 /// <summary>
 /// Clears the cache for the specified region.
 /// </summary>
 /// <param name="cacheRegion"></param>
 /// <returns></returns>
 internal static void ClearCacheForRegion(CacheRegion cacheRegion)
 {
     lock (_threadLock)
     {
         if (_cacheCollection != null && _cacheCollection.ContainsKey(cacheRegion))
             _cacheCollection.Remove(cacheRegion);
     }
 }
Пример #35
0
        /// <summary>
        /// Returns the cache for the specified region. A cache is created if one doesn't exist.
        /// </summary>
        /// <param name="cacheRegion"></param>
        /// <returns></returns>
        internal static MemoryCache GetCacheForRegion(CacheRegion cacheRegion)
        {
            lock (_threadLock)
            {
                if (_cacheCollection == null)
                    _cacheCollection = new Dictionary<CacheRegion, MemoryCache>();

                if (!_cacheCollection.ContainsKey(cacheRegion))
                    _cacheCollection.Add(cacheRegion, new MemoryCache("InfluenceHealth"));
            }

            return _cacheCollection[cacheRegion];
        }
Пример #36
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.String" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public override void BroadcastEvent(CacheRegion cacheRegion, String key, CacheEventType eventType)
 {
     mConnector.broadcastEvent(new com.tridion.cache.CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), key, (int)eventType));
 }
Пример #37
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public virtual void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
 }
Пример #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XmlCacheEvent" /> class.
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache Key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType"/></param>
 public XmlCacheEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     mRegionPath = CacheRegionExtensions.FromCacheRegion(cacheRegion);
     mKey = key.ToString();
     mEventType = eventType;
 }
Пример #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheEventArgs" /> class.
 /// </summary>
 /// <param name="region"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache item Key.</param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public CacheEventArgs(CacheRegion region, String key, CacheEventType eventType)
 {
     mRegion = region;
     mKey = key;
     mEventType = eventType;
 }
Пример #40
0
        /// <summary>
        /// Gets the specified key.
        /// </summary>
        /// <typeparam name="T">Cache item type</typeparam>
        /// <param name="key">Cache item key</param>
        /// <param name="valueInitializer">Cache item value initializer.</param>
        /// <returns>Cached item or newly created item</returns>
        public static T Get <T>(String key, Func <T> valueInitializer, CacheRegion cacheRegion, TcmUri cacheUri) where T : class
        {
            // No caching is applied
            if (mExpiration == -1)
            {
                return(valueInitializer());
            }

            MemoryCache cache = MemoryCache.Default;

            // Retrieve the value from the cache as the generic requested type
            var value = cache.Get(key);

            if (value != null)
            {
                T cachedItem = value as T;

                if (cachedItem != null)
                {
                    return(cachedItem);
                }

                return(default(T));
            }

            // Initialize the value if its not existing in the cache
            if (valueInitializer != null)
            {
                T initializedValue = valueInitializer();

                // Store the item in cache only if it returned an actual value
                if (!EqualityComparer <T> .Default.Equals(initializedValue, default(T)))
                {
                    CacheItemPolicy cacheItemPolicy = new CacheItemPolicy()
                    {
                        AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(Expiration),
                        RemovedCallback    = new CacheEntryRemovedCallback(ItemRemovedCallback)
                    };

                    if (cacheRegion != CacheRegion.Unknown)
                    {
                        String cacheKey = cacheUri.ToCacheKey();

                        TridionDependency dependency = mDependencies.FirstOrDefault(d => d.CacheRegion == cacheRegion && d.Key == cacheKey);

                        // Dependency did not exist yet, create it and add it to the cache dependencies list
                        if (dependency == null)
                        {
                            dependency = new TridionDependency(cacheRegion, cacheKey);
                            mDependencies.Add(dependency);
                        }

                        cacheItemPolicy.ChangeMonitors.Add(new TridionChangeMonitor(dependency));
                    }

                    cache.Set(key, initializedValue, cacheItemPolicy);
                    return(initializedValue);
                }
            }

            return(default(T));
        }
Пример #41
0
 public void Save(string key, object toSave, CacheRegion region, TimeSpan expiration)
 {
     _dictionary[key] = toSave;
 }
Пример #42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessCache"/> class.
 /// </summary>
 /// <param name="cacheRegion">Cache region.</param>
 /// <param name="disableForAdminUsers">Disable cache for admin users.</param>
 /// <param name="disableForStaffUsers">Disable cache for staff users</param>
 /// <param name="disableForPageEditors">Disable cache for page editors.</param>
 /// /// <param name="forceCache">Force the enabling of the cache for the current user.</param>
 public BusinessCache(CacheRegion cacheRegion, bool disableForAdminUsers, bool disableForStaffUsers, bool disableForPageEditors, bool forceCache)
     : this(cacheRegion, DefaultKeyPrefix, disableForAdminUsers, disableForStaffUsers, disableForPageEditors, forceCache)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TridionDependency"/> class.
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param>
 /// <param name="cacheKey">Cache Item Key</param>
 public TridionDependency(CacheRegion cacheRegion, String cacheKey)
 {
     mCacheRegion = cacheRegion;
     mKey = cacheKey;
 }
Пример #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XmlCacheEvent" /> class.
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache Key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType"/></param>
 public XmlCacheEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     mRegionPath = CacheRegionExtensions.FromCacheRegion(cacheRegion);
     mKey        = key.ToString();
     mEventType  = eventType;
 }
Пример #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessCache"/> class.
 /// </summary>
 /// <param name="cacheRegion">Cache region.</param>
 /// <param name="cacheKeyPrefix">The cache key prefix.</param>
 public BusinessCache(CacheRegion cacheRegion, string cacheKeyPrefix)
     : this(cacheRegion, cacheKeyPrefix, true, false, true, false)
 {
 }
Пример #46
0
 /// <summary>
 /// Trigger a CacheEvent for the <see cref="P:region" />, <see cref="P:key" /> and <see cref="P:eventType" />
 /// </summary>
 /// <param name="region"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param>
 /// <param name="key">Cache item key</param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param>
 protected void OnCacheEvent(CacheRegion region, String key, CacheEventType eventType)
 {
     if (CacheEvent != null)
         CacheEvent(null, new CacheEventArgs(region, key, eventType));
 }
Пример #47
0
 public static void ClearRegion(CacheRegion cacheRegion)
 {
     BusinessCache.ClearCacheForRegion(cacheRegion);
 }
Пример #48
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     mConnector.BroadcastEvent(new CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), key, eventType));
 }
Пример #49
0
 public static BusinessCache GetCache(CacheRegion cacheRegion, bool disableForAdminUsers, bool disableForStaffUsers, bool disableForPageEditors, bool forceCache)
 {
     return new BusinessCache(cacheRegion, disableForAdminUsers, disableForStaffUsers, disableForPageEditors, forceCache);
 }
Пример #50
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     mConnector.BroadcastEvent(new CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), key, eventType));
 }
Пример #51
0
 public static BusinessCache GetCache(CacheRegion cacheRegion, bool disableForAdminUsers, bool disableForStaffUsers, bool disableForPageEditors)
 {
     return MEDSEEK.eHealth.Utils.Business.Cache.CacheManager.GetCache(cacheRegion, disableForAdminUsers, disableForStaffUsers, disableForPageEditors);
 }
Пример #52
0
        /// <summary>
        /// Convert a <see cref="T:TcmCDService.CacheTypes.CacheRegion" /> value to a <see cref="T:System.String" />
        /// </summary>
        /// <param name="value"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
        /// <returns>Cache region as <see cref="T:System.String" /></returns>
        public static String FromCacheRegion(CacheRegion value)
        {
            String result;

            if (mReverse.TryGetValue(value, out result))
                return result;

            return null;
        }
Пример #53
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     mConnector.broadcastEvent(new com.tridion.cache.CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), new java.lang.Integer(key), (int)eventType));
 }
Пример #54
0
 /// <summary>
 /// Broadcasts a cache event to all other connected clients
 /// </summary>
 /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param>
 /// <param name="key">Cache key as <see cref="T:System.Int32" /></param>
 /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param>
 public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType)
 {
     XmlCacheEvent cacheEvent = new XmlCacheEvent(cacheRegion, key, eventType);
     BroadcastEvent(cacheEvent);
 }