/// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="saltKey">If you think the computed hash of the query to calculate the cache-key is not enough, set this value.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this IQueryable <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, string saltKey)
 {
     sanityCheck(query);
     return(query.TagWith(EFCachePolicy.Configure(options =>
                                                  options.ExpirationMode(expirationMode).Timeout(timeout).SaltKey(saltKey))));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="methodName">Tells the compiler to insert the name of the containing member instead of a parameter’s default value</param>
 /// <param name="lineNumber">Tells the compiler to insert the line number of the containing member instead of a parameter’s default value</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this IQueryable <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, [CallerMemberName] string methodName = null, [CallerLineNumber] int lineNumber = 0)
 {
     sanityCheck(query);
     return(query.markAsNoTracking().TagWith(EFCachePolicy.Configure(options =>
                                                                     options.ExpirationMode(expirationMode).Timeout(timeout).CallerMemberName(methodName).CallerLineNumber(lineNumber))));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="saltKey">If you think the computed hash of the query to calculate the cache-key is not enough, set this value.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this DbSet <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, string saltKey) where TType : class
 {
     sanityCheck(query);
     return(query.markAsNoTracking().TagWith(EFCachePolicy.Configure(options =>
                                                                     options.ExpirationMode(expirationMode).Timeout(timeout).SaltKey(saltKey))));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="cacheDependencies">
 /// Set this option to the `real` related table names of the current query, if you are using an stored procedure,
 /// otherswise cache dependencies of normal queries will be calculated automatically.
 /// `cacheDependencies` determines which tables are used in this final query.
 /// This array will be used to invalidate the related cache of all related queries automatically.
 /// </param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this DbSet <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, string[] cacheDependencies) where TType : class
 {
     sanityCheck(query);
     return(query.TagWith(EFCachePolicy.Configure(options =>
                                                  options.ExpirationMode(expirationMode).Timeout(timeout).CacheDependencies(cacheDependencies))));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this IQueryable <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout)
 {
     sanityCheck(query);
     return(query.markAsNoTracking().TagWith(EFCachePolicy.Configure(options =>
                                                                     options.ExpirationMode(expirationMode).Timeout(timeout))));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="cacheDependencies">
 /// Set this option to the `real` related table names of the current query, if you are using an stored procedure,
 /// otherswise cache dependencies of normal queries will be calculated automatically.
 /// `cacheDependencies` determines which tables are used in this final query.
 /// This array will be used to invalidate the related cache of all related queries automatically.
 /// </param>
 /// <param name="saltKey">If you think the computed hash of the query to calculate the cache-key is not enough, set this value.</param>
 /// <param name="methodName">Tells the compiler to insert the name of the containing member instead of a parameter’s default value</param>
 /// <param name="lineNumber">Tells the compiler to insert the line number of the containing member instead of a parameter’s default value</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable <TType> Cacheable <TType>(
     this DbSet <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, string[] cacheDependencies, string saltKey, [CallerMemberName] string methodName = null, [CallerLineNumber] int lineNumber = 0) where TType : class
 {
     sanityCheck(query);
     return(query.markAsNoTracking().TagWith(EFCachePolicy.Configure(options =>
                                                                     options.ExpirationMode(expirationMode).Timeout(timeout)
                                                                     .CacheDependencies(cacheDependencies).SaltKey(saltKey)
                                                                     .CallerMemberName(methodName).CallerLineNumber(lineNumber))));
 }
 /// <summary>
 /// Puts the whole system in cache. In this case calling the `Cacheable()` methods won't be necessary.
 /// If you specify the `Cacheable()` method, its setting will override this global setting.
 /// If you want to exclude some queries from this global cache, apply the `NotCacheable()` method to them.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 public EFCoreSecondLevelCacheOptions CacheAllQueries(CacheExpirationMode expirationMode, TimeSpan timeout)
 {
     Settings.CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
 /// <summary>
 /// Puts the whole system in cache just for the specified `entityTypes`.
 /// In this case calling the `Cacheable()` methods won't be necessary.
 /// If you specify the `Cacheable()` method, its setting will override this global setting.
 /// If you want to exclude some queries from this global cache, apply the `NotCacheable()` method to them.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="entityTypes">The real entity types. Queries containing these types will be cached.</param>
 public EFCoreSecondLevelCacheOptions CacheQueriesContainingTypes(
     CacheExpirationMode expirationMode, TimeSpan timeout, params Type[] entityTypes)
 {
     Settings.CacheSpecificQueriesOptions = new CacheSpecificQueriesOptions(entityTypes)
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
 /// <summary>
 /// Introduces the built-in `CacheManagerCoreProvider` to be used as the CacheProvider.
 /// If you specify the `Cacheable()` method options, its setting will override this global setting.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 public EFCoreSecondLevelCacheOptions UseCacheManagerCoreProvider(CacheExpirationMode expirationMode, TimeSpan timeout)
 {
     Settings.CacheProvider          = typeof(EFCacheManagerCoreProvider);
     Settings.CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
 /// <summary>
 /// You can introduce a custom IEFCacheServiceProvider to be used as the CacheProvider.
 /// If you specify the `Cacheable()` method options, its setting will override this global setting.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <typeparam name="T">Implements IEFCacheServiceProvider</typeparam>
 public EFCoreSecondLevelCacheOptions UseCustomCacheProvider <T>(CacheExpirationMode expirationMode, TimeSpan timeout) where T : IEFCacheServiceProvider
 {
     Settings.CacheProvider          = typeof(T);
     Settings.CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
 /// <summary>
 /// Introduces the built-in `EFMemoryCacheServiceProvider` to be used as the CacheProvider.
 /// If you specify the `Cacheable()` method options, its setting will override this global setting.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 public EFCoreSecondLevelCacheOptions UseMemoryCacheProvider(CacheExpirationMode expirationMode, TimeSpan timeout)
 {
     CacheProvider          = typeof(EFMemoryCacheServiceProvider);
     CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
 /// <summary>
 /// Puts the whole system in cache just for the specified `realTableNames`.
 /// In this case calling the `Cacheable()` methods won't be necessary.
 /// If you specify the `Cacheable()` method, its setting will override this global setting.
 /// If you want to exclude some queries from this global cache, apply the `NotCacheable()` method to them.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="realTableNames">
 /// The real table names.
 /// Queries containing these names will be cached.
 /// Table names are not case sensitive.
 /// </param>
 public EFCoreSecondLevelCacheOptions CacheQueriesContainingTableNames(
     CacheExpirationMode expirationMode, TimeSpan timeout, params string[] realTableNames)
 {
     Settings.CacheSpecificQueriesOptions = new CacheSpecificQueriesOptions(entityTypes: null)
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true,
         TableNames     = realTableNames
     };
     return(this);
 }
 /// <summary>
 /// Introduces the built-in `EFRedisCacheServiceProvider` to be used as the CacheProvider.
 /// If you specify the `Cacheable()` method options, its setting will override this global setting.
 /// </summary>
 /// <param name="configuration">The string configuration to use for the multiplexer.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 public EFCoreSecondLevelCacheOptions UseRedisCacheProvider(
     string configuration,
     CacheExpirationMode expirationMode,
     TimeSpan timeout)
 {
     CacheProvider          = typeof(EFRedisCacheServiceProvider);
     RedisConfiguration     = configuration;
     CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
Esempio n. 14
0
        private void LoadAttributes(XmlNode configNode, IFormatProvider formatProvider)
        {
            //Get the enableStateCache attribute
            XmlNode currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeEnableStateCache);

            if (currentAttribute != null)
            {
                _isStateCacheEnabled = Convert.ToBoolean(currentAttribute.Value, formatProvider);
            }

            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationMode);

            if (currentAttribute != null)
            {
                _defaultMode     = (CacheExpirationMode)Enum.Parse(typeof(CacheExpirationMode), currentAttribute.Value, true);
                currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationInterval);

                try
                {
                    switch (_defaultMode)
                    {
                    case CacheExpirationMode.Sliding:
                        _defaultInterval = new TimeSpan(0, 0, 0, 0, int.Parse(currentAttribute.Value, System.Globalization.CultureInfo.InvariantCulture));
                        break;

                    case CacheExpirationMode.Absolute:
                        _defaultInterval = TimeSpan.Parse(currentAttribute.Value);
                        if (_defaultInterval.Days > 0)
                        {
                            throw new ConfigurationException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionInvalidAbsoluteInterval]);
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    throw new ConfigurationException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionInvalidCacheExpirationInterval], e);
                }
            }

            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeAllowBackButton);

            if (currentAttribute != null)
            {
                _allowBackButton = Convert.ToBoolean(currentAttribute.Value, formatProvider);
            }
        }
 /// <summary>
 /// Introduces the built-in `EasyCachingCoreProvider` to be used as the CacheProvider.
 /// If you specify the `Cacheable()` method options, its setting will override this global setting.
 /// </summary>
 /// <param name="providerName">Selected caching provider name.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache items globally.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="isHybridCache">Is an instance of EasyCaching.HybridCache</param>
 public EFCoreSecondLevelCacheOptions UseEasyCachingCoreProvider(
     string providerName,
     CacheExpirationMode expirationMode,
     TimeSpan timeout,
     bool isHybridCache = false)
 {
     Settings.CacheProvider          = typeof(EFEasyCachingCoreProvider);
     Settings.ProviderName           = providerName;
     Settings.IsHybridCache          = isHybridCache;
     Settings.CacheAllQueriesOptions = new CacheAllQueriesOptions
     {
         ExpirationMode = expirationMode,
         Timeout        = timeout,
         IsActive       = true
     };
     return(this);
 }
Esempio n. 16
0
        /// <summary>
        /// Creates a new cache entry.
        /// </summary>
        /// <param name="mode">The cache expiration mode.</param>
        /// <param name="interval">The cache expiration interval.</param>
        /// <param name="cacheValue">The cache value.</param>
        /// <returns>A valid CacheEntry object.</returns>
        public static CacheEntry CreateCacheEntry(CacheExpirationMode mode, TimeSpan interval, object cacheValue)
        {
            DateTime now = DateTime.Now;

            switch (mode)
            {
            case CacheExpirationMode.Absolute:
                DateTime absoluteDate = new DateTime(now.Year, now.Month, now.Day).Add(interval);
                if (absoluteDate > now)
                {
                    return(new CacheEntry(cacheValue, absoluteDate));
                }
                else
                {
                    return(new CacheEntry(cacheValue, absoluteDate.AddDays(1)));
                }

            case CacheExpirationMode.Sliding:
                return(new CacheEntry(cacheValue, DateTime.Now.Add(interval)));

            default:
                return(new CacheEntry(cacheValue));
            }
        }
 /// <summary>
 /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static EFCachedQueryable <TType> Cacheable <TType>(
     this IQueryable <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, EFCacheDebugInfo debugInfo)
 {
     return(Cacheable(query, new EFCachePolicy(expirationMode, timeout), debugInfo));
 }
 /// <summary>
 /// EFCachePolicy determines the Expiration time of the cache.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="saltKey">If you think the computed hash of the query to calculate the cache-key is not enough, set this value.</param>
 public EFCachePolicy(CacheExpirationMode expirationMode, TimeSpan timeout, string saltKey)
 {
     ExpirationMode = expirationMode;
     Timeout        = timeout;
     SaltKey        = saltKey;
 }
Esempio n. 19
0
        /// <summary>
        /// Loads the remaining attributes from the configuration file.
        /// </summary>
        /// <param name="configNode">The XmlNode from the configuration file.</param>
        protected void LoadRemainingAttributes(XmlNode configNode)
        {
            XmlNode currentAttribute;

            //Read name attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeName);
            if (currentAttribute.Value.Trim().Length > 0)
            {
                _name = currentAttribute.Value;
            }
            else
            {
                throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionInvalidXmlAttributeValue, AttributeName, configNode.Name));
            }

            //Read state attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeState);
            if (currentAttribute.Value.Trim().Length > 0)
            {
                _state = currentAttribute.Value;
            }
            else
            {
                throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionInvalidXmlAttributeValue, AttributeState, configNode.Name));
            }

            //Read statePersist attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeStatePersist);
            if (currentAttribute.Value.Trim().Length > 0)
            {
                _statePersist = currentAttribute.Value;
            }
            else
            {
                throw new ConfigurationException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionInvalidXmlAttributeValue, AttributeStatePersist, configNode.Name));
            }

            //Read cache expiration attributes
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationMode);
            if (currentAttribute != null)
            {
                _expirationMode = (CacheExpirationMode)Enum.Parse(typeof(CacheExpirationMode), currentAttribute.Value, true);

                currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationInterval);
                try
                {
                    switch (_expirationMode)
                    {
                    case CacheExpirationMode.Sliding:
                        _expirationInterval = new TimeSpan(0, 0, 0, 0, int.Parse(currentAttribute.Value, System.Globalization.CultureInfo.InvariantCulture));
                        break;

                    case CacheExpirationMode.Absolute:
                        _expirationInterval = TimeSpan.Parse(currentAttribute.Value);
                        if (_expirationInterval.Days > 0)
                        {
                            throw new ConfigurationException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionInvalidAbsoluteInterval]);
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    throw new ConfigurationException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionInvalidCacheExpirationInterval], e);
                }
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Create a CacheConfiguration object.
 /// </summary>
 /// <param name="mode">The expiration mode for the cache. <see cref="CacheExpirationMode"/></param>
 /// <param name="interval">How often to check for expiration.</param>
 public CacheConfiguration(CacheExpirationMode mode, TimeSpan interval)
 {
     _mode = mode;
     _interval = interval;
 }
 /// <summary>
 /// EFCachePolicy determines the Expiration time of the cache.
 /// </summary>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 public EFCachePolicy(CacheExpirationMode expirationMode, TimeSpan timeout)
 {
     ExpirationMode = expirationMode;
     Timeout        = timeout;
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
 /// </summary>
 /// <typeparam name="TType">Entity type.</typeparam>
 /// <param name="query">The input EF query.</param>
 /// <param name="expirationMode">Defines the expiration mode of the cache item.</param>
 /// <param name="timeout">The expiration timeout.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static EFCachedDbSet <TType> Cacheable <TType>(
     this DbSet <TType> query, CacheExpirationMode expirationMode, TimeSpan timeout, EFCacheDebugInfo debugInfo) where TType : class
 {
     return(Cacheable(query, new EFCachePolicy(expirationMode, timeout), debugInfo));
 }
Esempio n. 23
0
        /// <summary>
        /// Loads the remaining attributes from the configuration file.
        /// </summary>
        /// <param name="configNode">The XmlNode from the configuration file.</param>
        protected void LoadRemainingAttributes(XmlNode configNode)
        {
            XmlNode currentAttribute;
            //Read name attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeName);
            if (currentAttribute.Value.Trim().Length > 0)
                _name = currentAttribute.Value;
            else
                throw new ConfigurationErrorsException(string.Format("ExceptionInvalidXmlAttributeValue {0} - {1}.",
                                                                     AttributeName, configNode.Name));

            //Read state attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeState);
            if (currentAttribute.Value.Trim().Length > 0)
                _state = currentAttribute.Value;
            else
                throw new ConfigurationErrorsException(string.Format("ExceptionInvalidXmlAttributeValue {0} - {1}.",
                                                                     AttributeState, configNode.Name));

            //Read statePersist attribute
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeStatePersist);
            if (currentAttribute.Value.Trim().Length > 0)
                _statePersist = currentAttribute.Value;
            else
                throw new ConfigurationErrorsException(string.Format("ExceptionInvalidXmlAttributeValue {0} - {1}.",
                                                                     AttributeStatePersist, configNode.Name));

            //Read cache expiration attributes
            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationMode);
            if( currentAttribute != null )
            {
                _expirationMode = (CacheExpirationMode)Enum.Parse( typeof( CacheExpirationMode), currentAttribute.Value, true );

                currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationInterval);
                try
                {
                    switch (_expirationMode)
                    {
                        case CacheExpirationMode.Sliding:
                            _expirationInterval = new TimeSpan( 0, 0, 0, 0, int.Parse( currentAttribute.Value, System.Globalization.CultureInfo.InvariantCulture ) );
                            break;
                        case CacheExpirationMode.Absolute:
                            _expirationInterval = TimeSpan.Parse( currentAttribute.Value );
                            if (_expirationInterval.Days > 0)
                                throw new ConfigurationErrorsException(string.Format("ExceptionInvalidAbsoluteInterval"));
                            break;
                    }
                }
                catch( Exception e )
                {
                    throw new ConfigurationErrorsException(string.Format("ExceptionInvalidCacheExpirationInterval {0}.", e.Message));
                }
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Create a CacheConfiguration object.
 /// </summary>
 /// <param name="mode">The expiration mode for the cache. <see cref="CacheExpirationMode"/></param>
 /// <param name="interval">How often to check for expiration.</param>
 public CacheConfiguration(CacheExpirationMode mode, TimeSpan interval)
 {
     _mode     = mode;
     _interval = interval;
 }
 /// <summary>
 /// Defines the expiration mode of the cache item.
 /// Its default value is Absolute.
 /// </summary>
 public EFCachePolicy ExpirationMode(CacheExpirationMode expirationMode)
 {
     CacheExpirationMode = expirationMode;
     return(this);
 }
Esempio n. 26
0
 public CacheExpirationPolicy(CacheExpirationMode expirationMode)
 {
     ExpirationMode = expirationMode;
 }
Esempio n. 27
0
        private void LoadAttributes(XmlNode configNode, IFormatProvider formatProvider)
        {
            //Get the enableStateCache attribute
            XmlNode currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeEnableStateCache);

            if(currentAttribute != null)
                _isStateCacheEnabled = Convert.ToBoolean(currentAttribute.Value,formatProvider);

            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationMode);

            if(currentAttribute != null)
            {
                _defaultMode = (CacheExpirationMode)Enum.Parse(typeof(CacheExpirationMode), currentAttribute.Value, true);
                currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeExpirationInterval);

                try
                {
                    switch(_defaultMode)
                    {
                        case CacheExpirationMode.Sliding:
                            _defaultInterval = new TimeSpan(0, 0, 0, 0, int.Parse(currentAttribute.Value, System.Globalization.CultureInfo.InvariantCulture));
                            break;
                        case CacheExpirationMode.Absolute:
                            _defaultInterval = TimeSpan.Parse(currentAttribute.Value);
                            if (_defaultInterval.Days > 0)
                                throw new ConfigurationErrorsException(string.Format("_ExceptionInvalidAbsoluteInterval"));
                            break;
                    }
                }
                catch(Exception e)
                {
                    throw new ConfigurationErrorsException(string.Format("ExceptionInvalidCacheExpirationInterval - {0}.", e.Message));
                }
            }

            currentAttribute = configNode.Attributes.RemoveNamedItem(AttributeAllowBackButton);

            if(currentAttribute != null)
                _allowBackButton = Convert.ToBoolean(currentAttribute.Value, formatProvider);
        }
Esempio n. 28
0
        /// <summary>
        /// Creates a new cache entry.
        /// </summary>
        /// <param name="mode">The cache expiration mode.</param>
        /// <param name="interval">The cache expiration interval.</param>
        /// <param name="cacheValue">The cache value.</param>
        /// <returns>A valid CacheEntry object.</returns>
        public static CacheEntry CreateCacheEntry(CacheExpirationMode mode, TimeSpan interval, object cacheValue)
        {
            DateTime now = DateTime.Now;
            switch (mode)
            {
                case CacheExpirationMode.Absolute:
                    DateTime absoluteDate = new DateTime(now.Year, now.Month, now.Day).Add(interval);
                    if (absoluteDate > now)
                        return new CacheEntry(cacheValue, absoluteDate);
                    else
                        return new CacheEntry(cacheValue, absoluteDate.AddDays(1));

                case CacheExpirationMode.Sliding:
                    return new CacheEntry(cacheValue, DateTime.Now.Add(interval));
                default:
                    return new CacheEntry(cacheValue);
            }
        }