/// <summary>
        /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
        /// </summary>
        /// <param name="query">The input EF query.</param>
        /// <param name="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
        /// <param name="debugInfo">Stores the debug information of the caching process.</param>
        /// <param name="serviceProvider">Defines a mechanism for retrieving a service object.</param>
        /// <returns></returns>
        public static IQueryable Cacheable(
            this IQueryable query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo, IServiceProvider serviceProvider)
        {
            var cacheServiceProvider = serviceProvider.GetRequiredService <IEFCacheServiceProvider>();
            var cacheKeyProvider     = serviceProvider.GetRequiredService <IEFCacheKeyProvider>();

            return(Cacheable(query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider));
        }
        /// <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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
        /// <param name="debugInfo">Stores the debug information of the caching process.</param>
        /// <param name="serviceProvider">Defines a mechanism for retrieving a service object.</param>
        /// <returns></returns>
        public static EFCachedQueryable <TType> Cacheable <TType>(
            this IQueryable <TType> query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo, IServiceProvider serviceProvider)
        {
            var cacheServiceProvider = serviceProvider.GetRequiredService <IEFCacheServiceProvider>();
            var cacheKeyProvider     = serviceProvider.GetRequiredService <IEFCacheKeyProvider>();

            return(new EFCachedQueryable <TType>(query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider));
        }
        /// <summary>
        /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
        /// </summary>
        /// <param name="query">The input EF query.</param>
        /// <param name="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
        /// <param name="debugInfo">Stores the debug information of the caching process.</param>
        /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
        /// <param name="cacheServiceProvider">Cache Service Provider.</param>
        /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
        public static IQueryable Cacheable(
            this IQueryable query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo,
            IEFCacheKeyProvider cacheKeyProvider, IEFCacheServiceProvider cacheServiceProvider)
        {
            var type            = typeof(EFCachedQueryable <>).MakeGenericType(query.ElementType);
            var cachedQueryable = Activator.CreateInstance(type, query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider);

            return(cachedQueryable as IQueryable);
        }
Exemple #4
0
 /// <summary>
 /// Defines methods to create and execute queries that are described by an System.Linq.IQueryable object.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">The Cache Service Provider.</param>
 public EFMaterializer(
     IQueryable query,
     EFCachePolicy cachePolicy,
     EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider,
     IEFCacheServiceProvider cacheServiceProvider)
 {
     _query                = query;
     _cachePolicy          = cachePolicy;
     _debugInfo            = debugInfo;
     _cacheKeyProvider     = cacheKeyProvider;
     _cacheServiceProvider = cacheServiceProvider;
 }
Exemple #5
0
 /// <summary>
 /// Defines methods to create and execute queries that are described by an System.Linq.IQueryable object.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">The Cache Service Provider.</param>
 public EFCachedQueryProvider(
     IQueryable <TType> query,
     EFCachePolicy cachePolicy,
     EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider,
     IEFCacheServiceProvider cacheServiceProvider)
 {
     _query                = query;
     _cachePolicy          = cachePolicy;
     _debugInfo            = debugInfo;
     _cacheKeyProvider     = cacheKeyProvider;
     _cacheServiceProvider = cacheServiceProvider;
 }
Exemple #6
0
 /// <summary>
 /// Provides functionality to evaluate queries against a specific data source.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">Cache Service Provider.</param>
 public EFCachedQueryable(
     IQueryable <TType> query,
     EFCachePolicy cachePolicy,
     EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider,
     IEFCacheServiceProvider cacheServiceProvider)
 {
     CachePolicy          = cachePolicy;
     DebugInfo            = debugInfo;
     CacheKeyProvider     = cacheKeyProvider;
     CacheServiceProvider = cacheServiceProvider;
     Query     = query.MarkAsNoTracking();
     _provider = new EFCachedQueryProvider(Query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider);
 }
 /// <summary>
 /// Provides functionality to evaluate queries against a specific data source.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">Cache Service Provider.</param>
 public EFCachedDbSet(
     DbSet <TType> query,
     EFCachePolicy cachePolicy,
     EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider,
     IEFCacheServiceProvider cacheServiceProvider)
 {
     CachePolicy          = cachePolicy;
     DebugInfo            = debugInfo;
     CacheKeyProvider     = cacheKeyProvider;
     CacheServiceProvider = cacheServiceProvider;
     Query     = query;
     _provider = new EFCachedQueryProvider <TType>(Query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider);
 }
        /// <summary>
        /// Provides functionality to evaluate queries against a specific data source.
        /// </summary>
        /// <param name="query">The input EF query.</param>
        /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
        /// <param name="debugInfo">Stores the debug information of the caching process.</param>
        /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
        /// <param name="cacheServiceProvider">Cache Service Provider.</param>
        public EFCachedDbSet(
            DbSet <TType> query,
            EFCachePolicy cachePolicy,
            EFCacheDebugInfo debugInfo,
            IEFCacheKeyProvider cacheKeyProvider,
            IEFCacheServiceProvider cacheServiceProvider)
        {
            CachePolicy          = cachePolicy;
            DebugInfo            = debugInfo;
            CacheKeyProvider     = cacheKeyProvider;
            CacheServiceProvider = cacheServiceProvider;
            Query = query;
            var queryable = Query.AsNoTracking().AsQueryable();

            ElementType = queryable.ElementType;
            Expression  = queryable.Expression;
            _provider   = new EFCachedQueryProvider(queryable, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider);
        }
        /// <summary>
        /// Adds a new item to the cache.
        /// </summary>
        /// <param name="cacheKey">key</param>
        /// <param name="value">value</param>
        /// <param name="rootCacheKeys">cache dependencies</param>
        /// <param name="cachePolicy">Defines the expiration mode of the cache item.</param>
        public void InsertValue(string cacheKey, object value, ISet <string> rootCacheKeys, EFCachePolicy cachePolicy)
        {
            if (value == null)
            {
                value = NullObject; // `HttpRuntime.Cache.Insert` won't accept null values.
            }

            foreach (var rootCacheKey in rootCacheKeys)
            {
                _dcReaderWriterLock.TryWriteLocked(() =>
                {
                    _dependenciesCacheManager.AddOrUpdate(rootCacheKey, new HashSet <string> {
                        cacheKey
                    },
                                                          updateValue: set =>
                    {
                        set.Add(cacheKey);
                        return(set);
                    });
                });
            }

            _vcmReaderWriterLock.TryWriteLocked(() =>
            {
                if (cachePolicy == null)
                {
                    _valuesCacheManager.Add(cacheKey, value);
                }
                else
                {
                    _valuesCacheManager.Add(new CacheItem <object>(
                                                cacheKey,
                                                value,
                                                cachePolicy.ExpirationMode == CacheExpirationMode.Absolute ? ExpirationMode.Absolute : ExpirationMode.Sliding,
                                                cachePolicy.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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">Cache Service Provider.</param>
 /// <returns></returns>
 public static EFCachedDbSet <TType> Cacheable <TType>(
     this DbSet <TType> query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider, IEFCacheServiceProvider cacheServiceProvider) where TType : class
 {
     return(new EFCachedDbSet <TType>(query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider));
 }
 /// <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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static EFCachedDbSet <TType> Cacheable <TType>(
     this DbSet <TType> query, EFCachePolicy cachePolicy) where TType : class
 {
     return(Cacheable(query, cachePolicy, new EFCacheDebugInfo()));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static IQueryable Cacheable(this IQueryable query, EFCachePolicy cachePolicy)
 {
     return(Cacheable(query, cachePolicy, new EFCacheDebugInfo()));
 }
 /// <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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
 /// <param name="debugInfo">Stores the debug information of the caching process.</param>
 /// <param name="cacheKeyProvider">Gets an EF query and returns its hash to store in the cache.</param>
 /// <param name="cacheServiceProvider">Cache Service Provider.</param>
 /// <returns></returns>
 public static EFCachedQueryable <TType> Cacheable <TType>(
     this IQueryable <TType> query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo,
     IEFCacheKeyProvider cacheKeyProvider, IEFCacheServiceProvider cacheServiceProvider)
 {
     return(new EFCachedQueryable <TType>(query, cachePolicy, debugInfo, cacheKeyProvider, cacheServiceProvider));
 }
 /// <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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</param>
 /// <returns>Provides functionality to evaluate queries against a specific data source.</returns>
 public static EFCachedQueryable <TType> Cacheable <TType>(this IQueryable <TType> query, EFCachePolicy cachePolicy)
 {
     return(Cacheable(query, cachePolicy, new EFCacheDebugInfo()));
 }
 /// <summary>
 /// Returns a new query where the entities returned will be cached in the IEFCacheServiceProvider.
 /// </summary>
 /// <param name="query">The input EF query.</param>
 /// <param name="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</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 IQueryable Cacheable(this IQueryable query, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo)
 {
     return(Cacheable(query, cachePolicy, debugInfo, _defaultCacheKeyProvider, _defaultCacheServiceProvider));
 }
 /// <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="cachePolicy">Defines the expiration mode of the cache item. If you set it to null or don't specify it, the global `new CacheManager.Core.ConfigurationBuilder().WithExpiration()` setting will be used automatically.</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, EFCachePolicy cachePolicy, EFCacheDebugInfo debugInfo) where TType : class
 {
     return(Cacheable(query, cachePolicy, debugInfo, _defaultCacheKeyProvider, _defaultCacheServiceProvider));
 }