public void Add(ICacheKey cacheKey, object value, ICacheDependency dependency, DateTime expirationDate, TimeSpan slidingSpan, RuntimeCommon.Caching.CacheItemPriority priority) { var policy = new CacheItemPolicy(); { //configurations var depKeys = TransformDependency(dependency)?.ToList(); if (!depKeys.IsNullOrEmpty()) { foreach (var key in depKeys) { subscription.SubscribeTopic(key); } var monitor = new PubSubMonitor(cacheKey.GetKeyAsString(), depKeys, filter); policy.ChangeMonitors.Add(monitor); } policy.SlidingExpiration = slidingSpan == CacheUtils.NoSliding ? ObjectCache.NoSlidingExpiration : slidingSpan; policy.AbsoluteExpiration = expirationDate == CacheUtils.NoExpiration ? ObjectCache.InfiniteAbsoluteExpiration : expirationDate; policy.Priority = priority == RuntimeCommon.Caching.CacheItemPriority.NotRemovable ? System.Runtime.Caching.CacheItemPriority.NotRemovable : System.Runtime.Caching.CacheItemPriority.Default; } memoryCacheInstance.Set(cacheKey.GetKeyAsString(), value, policy); }
public void Listen(ICacheKey cacheKey, ICacheDependency dependency, CacheItemInvalidationCallback invalidationCallback) { var policy = new CacheItemPolicy(); { //configurations var depKeys = TransformDependency(dependency)?.ToList(); if (!depKeys.IsNullOrEmpty()) { foreach (var key in depKeys) { subscription.SubscribeTopic(key); } var monitor = new PubSubMonitor(cacheKey.GetKeyAsString(), depKeys, filter); policy.ChangeMonitors.Add(monitor); } policy.SlidingExpiration = ObjectCache.NoSlidingExpiration; policy.AbsoluteExpiration = DateTime.UtcNow.AddDays(1); policy.Priority = System.Runtime.Caching.CacheItemPriority.NotRemovable; policy.UpdateCallback = EncapsulateListenerCallback(cacheKey, depKeys, invalidationCallback); } memoryCacheInstance.Set(cacheKey.GetKeyAsString(), 0, policy); }