@@ -166,7 +166,7 @@ protected virtual MediaTypeHeaderValue GetExpectedMediaType(HttpConfiguration co
166166 return responseMediaType ;
167167 }
168168
169- public override void OnActionExecuting ( HttpActionContext actionContext )
169+ public override async Task OnActionExecutingAsync ( HttpActionContext actionContext , CancellationToken cancellationToken )
170170 {
171171 if ( actionContext == null ) throw new ArgumentNullException ( "actionContext" ) ;
172172
@@ -183,11 +183,11 @@ public override void OnActionExecuting(HttpActionContext actionContext)
183183 actionContext . Request . Properties [ CurrentRequestMediaType ] = responseMediaType ;
184184 var cachekey = cacheKeyGenerator . MakeCacheKey ( actionContext , responseMediaType , ExcludeQueryStringFromCacheKey ) ;
185185
186- if ( ! _webApiCache . Contains ( cachekey ) ) return ;
186+ if ( await _webApiCache . ContainsAsync ( cachekey ) == false ) return ;
187187
188188 if ( actionContext . Request . Headers . IfNoneMatch != null )
189189 {
190- var etag = _webApiCache . Get < string > ( cachekey + Constants . EtagKey ) ;
190+ var etag = await _webApiCache . GetAsync < string > ( cachekey + Constants . EtagKey ) ;
191191 if ( etag != null )
192192 {
193193 if ( actionContext . Request . Headers . IfNoneMatch . Any ( x => x . Tag == etag ) )
@@ -203,11 +203,11 @@ public override void OnActionExecuting(HttpActionContext actionContext)
203203 }
204204 }
205205
206- var val = _webApiCache . Get < byte [ ] > ( cachekey ) ;
206+ var val = await _webApiCache . GetAsync < byte [ ] > ( cachekey ) ;
207207 if ( val == null ) return ;
208208
209- var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
210- var contentGeneration = _webApiCache . Get < string > ( cachekey + Constants . GenerationTimestampKey ) ;
209+ var contenttype = await _webApiCache . GetAsync < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
210+ var contentGeneration = await _webApiCache . GetAsync < string > ( cachekey + Constants . GenerationTimestampKey ) ;
211211
212212 DateTimeOffset ? contentGenerationTimestamp = null ;
213213 if ( contentGeneration != null )
@@ -222,7 +222,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
222222 actionContext . Response . Content = new ByteArrayContent ( val ) ;
223223
224224 actionContext . Response . Content . Headers . ContentType = contenttype ;
225- var responseEtag = _webApiCache . Get < string > ( cachekey + Constants . EtagKey ) ;
225+ var responseEtag = await _webApiCache . GetAsync < string > ( cachekey + Constants . EtagKey ) ;
226226 if ( responseEtag != null ) SetEtag ( actionContext . Response , responseEtag ) ;
227227
228228 var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
@@ -246,7 +246,7 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
246246 var responseMediaType = actionExecutedContext . Request . Properties [ CurrentRequestMediaType ] as MediaTypeHeaderValue ?? GetExpectedMediaType ( httpConfig , actionExecutedContext . ActionContext ) ;
247247 var cachekey = cacheKeyGenerator . MakeCacheKey ( actionExecutedContext . ActionContext , responseMediaType , ExcludeQueryStringFromCacheKey ) ;
248248
249- if ( ! string . IsNullOrWhiteSpace ( cachekey ) && ! ( _webApiCache . Contains ( cachekey ) ) )
249+ if ( ! string . IsNullOrWhiteSpace ( cachekey ) && ! ( await _webApiCache . ContainsAsync ( cachekey ) ) )
250250 {
251251 SetEtag ( actionExecutedContext . Response , CreateEtag ( actionExecutedContext , cachekey , cacheTime ) ) ;
252252
@@ -262,16 +262,14 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
262262
263263 responseContent . Headers . Remove ( "Content-Length" ) ;
264264
265- _webApiCache . Add ( baseKey , string . Empty , cacheTime . AbsoluteExpiration ) ;
266- _webApiCache . Add ( cachekey , content , cacheTime . AbsoluteExpiration , baseKey ) ;
267-
265+ await _webApiCache . AddAsync ( baseKey , string . Empty , cacheTime . AbsoluteExpiration ) ;
266+ await _webApiCache . AddAsync ( cachekey , content , cacheTime . AbsoluteExpiration , baseKey ) ;
268267
269- _webApiCache . Add ( cachekey + Constants . ContentTypeKey ,
268+ await _webApiCache . AddAsync ( cachekey + Constants . ContentTypeKey ,
270269 contentType ,
271270 cacheTime . AbsoluteExpiration , baseKey ) ;
272-
273-
274- _webApiCache . Add ( cachekey + Constants . EtagKey ,
271+
272+ await _webApiCache . AddAsync ( cachekey + Constants . EtagKey ,
275273 etag ,
276274 cacheTime . AbsoluteExpiration , baseKey ) ;
277275
0 commit comments