Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

CachePolicy with default cache key strategy results in the cache never been called #106

Closed
ymor opened this issue Apr 30, 2018 · 4 comments

Comments

@ymor
Copy link

ymor commented Apr 30, 2018

The DefaultCacheKeyStrategy uses the ExecutionKey from the Polly Context. However this seems to never get set and so the Polly CacheEngineAsync never tries the cache.

There doesn't seem to be enough information on the Context to even create a custom CacheKeyStrategy. Is it possible to add some of the request information onto the Context?

@reisenberger
Copy link
Contributor

@ymor Before placing the call through HttpClient, you can use this extension method on HttpRequestMessage to set the Polly.Context to use with the request.

request.SetPolicyExecutionContext(new Polly.Context("CacheKeyToUseWithThisRequest"));

That example assumes your CachePolicy is using the default cache key strategy. If you use a custom cache key strategy you can vary the Context you pass to request.SetPolicyExecutionContext(...); to fit your custom strategy.

@rynowak @stevejgordon We need to get this in the documentation, whether Polly's (I'll draft something there) or the official aspnet/docs version.

@reisenberger
Copy link
Contributor

I have added some initial notes here in Polly's doco around IHttpClientFactory and Polly CachePolicy. The doco notes some considerations around caching at the low level of the raw HttpResponseMessage.

@ymor
Copy link
Author

ymor commented May 1, 2018

Thanks, those considerations were things i hadn't thought about!

@mkArtakMSFT
Copy link
Member

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants