コード例 #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));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #5
0
 /// <inheritdoc cref="ISyncCachedQuery{TContext,TCacheEntryOptions,TResult}.Execute"/>
 public virtual TResult Execute(TContext context, ISyncCacheStore <TCacheEntryOptions> cacheStore, CacheOption cacheOption) =>
 GetCachedResult(context, cacheStore, cacheOption);