/// <summary>
 /// Adds an object into cache based on the parameters provided.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="name">The name.</param>
 /// <param name="itemPolicy">The itemPolicy object.</param>
 /// <param name="value">The value to store in cache.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <returns></returns>
 public object Set(object tag, string name, CacheItemPolicy itemPolicy, object value, ServiceCacheByDispatcher dispatch)
 {
     if (itemPolicy == null)
         throw new ArgumentNullException("itemPolicy");
     var updateCallback = itemPolicy.UpdateCallback;
     if (updateCallback != null)
         updateCallback(name, value);
     //
     if (itemPolicy.SlidingExpiration != ServiceCache.NoSlidingExpiration)
         throw new ArgumentOutOfRangeException("itemPolicy.SlidingExpiration", "not supported.");
     if (itemPolicy.RemovedCallback != null)
         throw new ArgumentOutOfRangeException("itemPolicy.RemovedCallback", "not supported.");
     //
     var oldVersion = (tag as DataCacheItemVersion);
     var lockHandle = (tag as DataCacheLockHandle);
     var dataCacheTags = GetCacheDependency(tag, itemPolicy.Dependency, dispatch);
     var timeout = GetTimeout(itemPolicy.AbsoluteExpiration);
     string regionName;
     if (timeout == TimeSpan.Zero && dataCacheTags == null)
         if (oldVersion == null && lockHandle == null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value);
             else Cache.Put(name, value, regionName);
         }
         else if (oldVersion != null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, oldVersion);
             else Cache.Put(name, value, oldVersion, regionName);
         }
         else
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.PutAndUnlock(name, value, lockHandle);
             else Cache.PutAndUnlock(name, value, lockHandle, regionName);
         }
     else if (timeout != TimeSpan.Zero && dataCacheTags == null)
         if ((oldVersion == null) && (lockHandle == null))
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, timeout);
             else Cache.Put(name, value, timeout, regionName);
         }
         else if (oldVersion != null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, oldVersion, timeout);
             else Cache.Put(name, value, oldVersion, timeout, regionName);
         }
         else
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.PutAndUnlock(name, value, lockHandle, timeout);
             else Cache.PutAndUnlock(name, value, lockHandle, timeout, regionName);
         }
     else if (timeout == TimeSpan.Zero && dataCacheTags != null)
         if ((oldVersion == null) && (lockHandle == null))
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, dataCacheTags);
             else Cache.Put(name, value, dataCacheTags, regionName);
         }
         else if (oldVersion != null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, oldVersion, dataCacheTags);
             else Cache.Put(name, value, oldVersion, dataCacheTags, regionName);
         }
         else
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.PutAndUnlock(name, value, lockHandle, dataCacheTags);
             else Cache.PutAndUnlock(name, value, lockHandle, dataCacheTags, regionName);
         }
     else
         if (oldVersion == null && lockHandle == null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, timeout, dataCacheTags);
             else Cache.Put(name, value, timeout, dataCacheTags, regionName);
         }
         else if (oldVersion != null)
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Put(name, value, oldVersion, timeout, dataCacheTags);
             else Cache.Put(name, value, oldVersion, timeout, dataCacheTags, regionName);
         }
         else
         {
             if (!Settings.TryGetRegion(ref name, out regionName)) Cache.PutAndUnlock(name, value, lockHandle, timeout, dataCacheTags);
             else Cache.PutAndUnlock(name, value, lockHandle, timeout, dataCacheTags, regionName);
         }
     //
     var registration = dispatch.Registration;
     if (registration != null && registration.UseHeaders)
     {
         var header = dispatch.Header;
         header.Item = name;
         Add(tag, name + "#", CacheItemPolicy.Default, header, ServiceCacheByDispatcher.Empty);
     }
     return value;
 }
Пример #2
0
 /// <summary>
 /// Adds an object into cache based on the parameters provided.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="name">The name.</param>
 /// <param name="itemPolicy">The itemPolicy object.</param>
 /// <param name="value">The value to store in cache.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <returns></returns>
 public object Set(object tag, string name, CacheItemPolicy itemPolicy, object value, ServiceCacheByDispatcher dispatch)
 {
     if (itemPolicy == null)
         throw new ArgumentNullException("itemPolicy");
     var updateCallback = itemPolicy.UpdateCallback;
     if (updateCallback != null)
         updateCallback(name, value);
     //
     throw new NotImplementedException();
 }
Пример #3
0
 /// <summary>
 /// Adds an object into cache based on the parameters provided.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="name">The name.</param>
 /// <param name="itemPolicy">The itemPolicy object.</param>
 /// <param name="value">The value to store in cache.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <returns></returns>
 public object Set(object tag, string name, CacheItemPolicy itemPolicy, object value, ServiceCacheByDispatcher dispatch)
 {
     if (itemPolicy == null)
         throw new ArgumentNullException("itemPolicy");
     var updateCallback = itemPolicy.UpdateCallback;
     if (updateCallback != null)
         updateCallback(name, value);
     // item priority
     WebCacheItemPriority cacheItemPriority;
     switch (itemPolicy.Priority)
     {
         case CacheItemPriority.AboveNormal: cacheItemPriority = WebCacheItemPriority.AboveNormal; break;
         case CacheItemPriority.BelowNormal: cacheItemPriority = WebCacheItemPriority.BelowNormal; break;
         case CacheItemPriority.High: cacheItemPriority = WebCacheItemPriority.High; break;
         case CacheItemPriority.Low: cacheItemPriority = WebCacheItemPriority.Low; break;
         case CacheItemPriority.Normal: cacheItemPriority = WebCacheItemPriority.Normal; break;
         case CacheItemPriority.NotRemovable: cacheItemPriority = WebCacheItemPriority.NotRemovable; break;
         default: cacheItemPriority = WebCacheItemPriority.Default; break;
     }
     //
     var removedCallback = (itemPolicy.RemovedCallback == null ? null : new WebCacheItemRemovedCallback((n, v, c) => { itemPolicy.RemovedCallback(n, v); }));
     Cache.Insert(name, value, GetCacheDependency(tag, itemPolicy.Dependency, dispatch), itemPolicy.AbsoluteExpiration, itemPolicy.SlidingExpiration, cacheItemPriority, removedCallback);
     var registration = dispatch.Registration;
     if (registration != null && registration.UseHeaders)
     {
         var headerPolicy = new WebCacheDependency(null, new[] { name });
         var header = dispatch.Header;
         header.Item = name;
         Cache.Insert(name + "#", header, headerPolicy, itemPolicy.AbsoluteExpiration, itemPolicy.SlidingExpiration, cacheItemPriority, null);
     }
     return value;
 }
Пример #4
0
 /// <summary>
 /// Adds the specified tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="name">The name.</param>
 /// <param name="itemPolicy">The item policy.</param>
 /// <param name="value">The value.</param>
 /// <param name="dispatch">The dispatch.</param>
 /// <returns></returns>
 public object Add(object tag, string name, CacheItemPolicy itemPolicy, object value, ServiceCacheByDispatcher dispatch)
 {
     if (itemPolicy == null)
         throw new ArgumentNullException("itemPolicy");
     var updateCallback = itemPolicy.UpdateCallback;
     if (updateCallback != null)
         updateCallback(name, value);
     //
     if (itemPolicy.SlidingExpiration != ServiceCache.NoSlidingExpiration)
         throw new ArgumentOutOfRangeException("itemPolicy.SlidingExpiration", "not supported.");
     if (itemPolicy.RemovedCallback != null)
         throw new ArgumentOutOfRangeException("itemPolicy.RemovedCallback", "not supported.");
     //
     throw new NotImplementedException();
 }