@@ -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 ) )
@@ -201,16 +201,16 @@ public override void OnActionExecuting(HttpActionContext actionContext)
201201 }
202202 }
203203
204- var val = _webApiCache . Get < byte [ ] > ( cachekey ) ;
204+ var val = await _webApiCache . GetAsync < byte [ ] > ( cachekey ) ;
205205 if ( val == null ) return ;
206206
207- var contenttype = _webApiCache . Get < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
207+ var contenttype = await _webApiCache . GetAsync < MediaTypeHeaderValue > ( cachekey + Constants . ContentTypeKey ) ?? responseMediaType ;
208208
209209 actionContext . Response = actionContext . Request . CreateResponse ( ) ;
210210 actionContext . Response . Content = new ByteArrayContent ( val ) ;
211211
212212 actionContext . Response . Content . Headers . ContentType = contenttype ;
213- var responseEtag = _webApiCache . Get < string > ( cachekey + Constants . EtagKey ) ;
213+ var responseEtag = await _webApiCache . GetAsync < string > ( cachekey + Constants . EtagKey ) ;
214214 if ( responseEtag != null ) SetEtag ( actionContext . Response , responseEtag ) ;
215215
216216 var cacheTime = CacheTimeQuery . Execute ( DateTime . Now ) ;
@@ -233,7 +233,7 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
233233 var responseMediaType = actionExecutedContext . Request . Properties [ CurrentRequestMediaType ] as MediaTypeHeaderValue ?? GetExpectedMediaType ( httpConfig , actionExecutedContext . ActionContext ) ;
234234 var cachekey = cacheKeyGenerator . MakeCacheKey ( actionExecutedContext . ActionContext , responseMediaType , ExcludeQueryStringFromCacheKey ) ;
235235
236- if ( ! string . IsNullOrWhiteSpace ( cachekey ) && ! ( _webApiCache . Contains ( cachekey ) ) )
236+ if ( ! string . IsNullOrWhiteSpace ( cachekey ) && ! ( await _webApiCache . ContainsAsync ( cachekey ) ) )
237237 {
238238 SetEtag ( actionExecutedContext . Response , CreateEtag ( actionExecutedContext , cachekey , cacheTime ) ) ;
239239
@@ -249,16 +249,14 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
249249
250250 responseContent . Headers . Remove ( "Content-Length" ) ;
251251
252- _webApiCache . Add ( baseKey , string . Empty , cacheTime . AbsoluteExpiration ) ;
253- _webApiCache . Add ( cachekey , content , cacheTime . AbsoluteExpiration , baseKey ) ;
254-
252+ await _webApiCache . AddAsync ( baseKey , string . Empty , cacheTime . AbsoluteExpiration ) ;
253+ await _webApiCache . AddAsync ( cachekey , content , cacheTime . AbsoluteExpiration , baseKey ) ;
255254
256- _webApiCache . Add ( cachekey + Constants . ContentTypeKey ,
255+ await _webApiCache . AddAsync ( cachekey + Constants . ContentTypeKey ,
257256 contentType ,
258257 cacheTime . AbsoluteExpiration , baseKey ) ;
259-
260-
261- _webApiCache . Add ( cachekey + Constants . EtagKey ,
258+
259+ await _webApiCache . AddAsync ( cachekey + Constants . EtagKey ,
262260 etag ,
263261 cacheTime . AbsoluteExpiration , baseKey ) ;
264262 }
0 commit comments