internal void FinalizeCacheHeaders(ResponseCachingContext context)
 {
     if (OnFinalizeCacheHeaders(context))
     {
         _cache.Set(context.BaseKey, context.CachedVaryByRules, context.CachedResponseValidFor);
     }
 }
        public void SetInvalidCacheEntryTypeThrowsException()
        {
            var unsupportedCacheEntry = new UnsupportedResponseCacheEntry();

            Assert.Throws <InvalidOperationException>(() =>
                                                      _distributedResponseCache.Set(Key, unsupportedCacheEntry, default(TimeSpan)));
        }
예제 #3
0
        public void SetCallsSerializerAndCache()
        {
            _distributedResponseCache.Set(Key, _deserializedValue, default(TimeSpan));

            A.CallTo(() => _fakeCacheSerializer.Serialize(_deserializedValue))
            .MustHaveHappenedOnceExactly();

            A.CallTo(() => _fakeDistributedCache.Set(Key, _serializedValue, A <DistributedCacheEntryOptions> ._))
            .MustHaveHappenedOnceExactly();
        }
예제 #4
0
        private void AddToCache(Response response)
        {
            if (!UseCache)
            {
                return;
            }

            if (response.Questions.Count == 0)
            {
                return;
            }

            var question = response.Questions[0];

            _cache.Set(question, response);
        }
        public async Task <T> Please()
        {
            T   cachedResult;
            var foundInCache = _responseCache.TryGet(_requestData, out cachedResult);

            if (foundInCache)
            {
                return(cachedResult);
            }

            Response response = await Response();

            var result = _parser.Parse <T>(response);

            // set to cache only after all validation and parsing has succeeded
            _responseCache.Set(_requestData, result);

            return(result);
        }