Exemplo n.º 1
0
 protected CacheProvider(CacheOptions options)
 {
     if (options != null)
     {
         _cacheNamespace = options.Namespace;
         _userContext = options.UserContext;
         _slidingExpiration = options.SlidingExpiration;
         if (options.LifeSpan.HasValue)
         {
             LifeSpan = options.LifeSpan;
         }
         else if (options.ExpiresAt.HasValue)
         {
             ExpiresAt = options.ExpiresAt;
             if (_slidingExpiration)
             {
                 LifeSpan = ExpiresAt.Subtract(DateTimeOffset.Now);
             }
         }
         else if (options.TimeOfDay.NullIfEmpty() != null)
         {
             TimeOfDay = options.TimeOfDay;
             if (_slidingExpiration && ExpiresAtSpecificTime.HasValue)
             {
                 LifeSpan = ExpiresAtSpecificTime.Value.Subtract(DateTimeOffset.Now);
             }
         }
     }
 }
Exemplo n.º 2
0
 public static CacheProvider GetProvider(Type cacheType, CacheOptions options = null)
 {
     if (cacheType != null && typeof(CacheProvider).IsAssignableFrom(cacheType))
     {
         var activator = Nemo.Reflection.Activator.CreateDelegate(cacheType, typeof(CacheOptions));
         if (activator != null)
         {
             return (CacheProvider)activator(options);
         }
     }
     return null;
 }
Exemplo n.º 3
0
 public CacheScope(bool buffered = true, Type cacheType = null, CacheOptions options = null, CacheDependency[] dependencies = null)
 {
     Provider = CacheFactory.GetProvider(cacheType, options);
     Buffered = buffered;
     if (Buffered)
     {
         // No reason to buffer in-process cache
         if (Provider != null && !Provider.IsOutOfProcess)
         {
             Buffered = false;
         }
     }
     HashAlgorithm = options != null && options.HashAlgorithm.HasValue ? options.HashAlgorithm.Value : HashAlgorithmName.Default;
     Dependencies = dependencies;
     CacheScope.Scopes.Push(this);
 }