Esempio n. 1
0
        /// <inheritdoc cref="ISyncCachedQuery{TContext,TCacheEntryOptions,TResult}.Execute"/>
        protected virtual TCachedResult GetCachedResult(TContext context, ISyncCacheStore <TCacheEntryOptions> cacheStore, CacheOption cacheOption)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (cacheStore == null)
            {
                throw new ArgumentNullException(nameof(cacheStore));
            }

            State.SetContext(context);

            if (cacheOption == CacheOption.Default)
            {
                var cacheEntry = cacheStore.GetEntry <TCachedResult>(State.CacheKey);
                if (cacheEntry != null)
                {
                    return(State.SetCachedResult(cacheEntry.Value));
                }
            }

            var result = Query(context);

            cacheStore.SetEntry(State.CacheKey, result.ToCacheEntry(), State.CacheEntryOptions);
            return(State.SetCachedResult(result));
        }
Esempio n. 2
0
        /// <inheritdoc cref="ISyncCachedQuery{TCacheEntryOptions}.UpdateCachedResult"/>
        public virtual void UpdateCachedResult(ISyncCacheStore <TCacheEntryOptions> cacheStore)
        {
            if (cacheStore == null)
            {
                throw new ArgumentNullException(nameof(cacheStore));
            }

            cacheStore.SetEntry(State.CacheKey, State.CachedResult.ToCacheEntry(), State.CacheEntryOptions);
        }
Esempio n. 3
0
        /// <inheritdoc cref="ISyncCachedQuery{TCacheEntryOptions}.EvictCachedResult"/>
        public virtual void EvictCachedResult(ISyncCacheStore <TCacheEntryOptions> cacheStore)
        {
            if (cacheStore == null)
            {
                throw new ArgumentNullException(nameof(cacheStore));
            }

            cacheStore.RemoveEntry(State.CacheKey);
        }
Esempio n. 4
0
        /// <inheritdoc cref="ISyncCachedQuery{TContext,TCacheEntryOptions,TResult}.Execute"/>
        public virtual TTransformedResult Execute(TContext context, ISyncCacheStore <TCacheEntryOptions> cacheStore, CacheOption cacheOption)
        {
            var cachedResult = GetCachedResult(context, cacheStore, cacheOption);

            return(TransformCachedResult(cachedResult));
        }
Esempio n. 5
0
 /// <inheritdoc cref="ISyncCachedQuery{TContext,TCacheEntryOptions,TResult}.Execute"/>
 public virtual TResult Execute(TContext context, ISyncCacheStore <TCacheEntryOptions> cacheStore, CacheOption cacheOption) =>
 GetCachedResult(context, cacheStore, cacheOption);