Example #1
0
 private static T GetUsingRwLock <T>(IServiceCache cache, ServiceCacheRegistration registration, object tag, object[] values, string name, string @namespace, bool useDBNull)
 {
     _rwLock.EnterUpgradeableReadLock();
     try
     {
         CacheItemHeader header;
         var             valueAsCache = cache.Get(tag, name, registration, out header);
         if (valueAsCache != null && (!registration.UseHeaders || header != null))
         {
             return(!useDBNull || !(valueAsCache is DBNull) ? (T)valueAsCache : default(T));
         }
         _rwLock.EnterWriteLock();
         try
         {
             valueAsCache = cache.Get(tag, name, registration, out header);
             if (valueAsCache != null && (!registration.UseHeaders || header != null))
             {
                 return(!useDBNull || !(valueAsCache is DBNull) ? (T)valueAsCache : default(T));
             }
             // create
             var value = CreateData <T>(@namespace, registration, tag, values, out header);
             valueAsCache = (!useDBNull || value != null ? (object)value : DBNull.Value);
             cache.Add(tag, name, registration.ItemPolicy, valueAsCache, new ServiceCacheByDispatcher(registration, values, header));
             return(value);
         }
         finally { _rwLock.ExitWriteLock(); }
     }
     finally { _rwLock.ExitUpgradeableReadLock(); }
 }
Example #2
0
 private static void SetUsingLock(IServiceCache cache, ServiceCacheRegistration registration, object tag, CacheItemHeader header, bool useDBNull, object value)
 {
     lock (_rwLock)
     {
         var valueAsCache = (!useDBNull || value != null ? (object)value : DBNull.Value);
         cache.Add(tag, header.Item, registration.ItemPolicy, valueAsCache, new ServiceCacheByDispatcher(registration, header.Values, header));
     }
 }
Example #3
0
 private static void SetUsingRwLock(IServiceCache cache, ServiceCacheRegistration registration, object tag, CacheItemPolicy itemPolicy, CacheItemHeader header, bool useDBNull, object value)
 {
     _rwLock.EnterWriteLock();
     try
     {
         var valueAsCache = (!useDBNull || value != null ? (object)value : DBNull.Value);
         cache.Add(tag, header.Item, itemPolicy, valueAsCache, new ServiceCacheByDispatcher(registration, header.Values, header));
     }
     finally { _rwLock.ExitWriteLock(); }
 }
Example #4
0
 private static T CreateData <T>(string @namespace, ServiceCacheRegistration registration, object tag, object[] values, out CacheItemHeader header)
 {
     if (@namespace != null)
     {
         var namespaces = registration.Namespaces;
         if (!namespaces.Contains(@namespace))
         {
             namespaces.Add(@namespace);
         }
     }
     header = new CacheItemHeader {
         Values = values,
     };
     return((T)registration.Builder(tag, values));
 }
Example #5
0
        private static T GetUsingCas <T>(IDistributedServiceCache cache, ServiceCacheRegistration registration, object tag, object[] values, string name, string @namespace, bool useDBNull)
        {
            CacheItemHeader header;
            var             valueAsCache = cache.Get(tag, name, registration, out header);

            if (valueAsCache != null && (!registration.UseHeaders || header != null))
            {
                return(!useDBNull || !(valueAsCache is DBNull) ? (T)valueAsCache : default(T));
            }
            // create
            var value = CreateData <T>(@namespace, registration, tag, values, out header);

            valueAsCache = (!useDBNull || value != null ? (object)value : DBNull.Value);
            cache.Add(tag, name, registration.ItemPolicy, valueAsCache, new ServiceCacheByDispatcher(registration, values, header));
            return(value);
        }
 /// <summary>
 /// Gets the query.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="registration">The registration.</param>
 /// <param name="tag">The tag.</param>
 /// <param name="values">The values.</param>
 /// <returns></returns>
 public static IQueryable <T> GetQuery <T>(ServiceCacheRegistration registration, object tag, object[] values)
 {
     return(ServiceCacheManager.Current.Get <IQueryable <T> >(registration, tag, values));
 }