question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can Polly's Caching Policy cache selectively based on response? (eg cache only 200ok http responses)

See original GitHub issue

Is Polly able to cache selectively based off of parameters like response code, response headers, etc



I could not find any documentation on what types of responses Polly decides to cache, or whether it’s possible to cache selectively based on attributes like the response code. Right now a workaround I’ve tried is using ResultTtl to vary the ttl based on response code, and setting a very short ttl for non 200 responses.

Is there any good way to have the cache policy ignore all responses that are not 200?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
reisenbergercommented, Sep 17, 2019

@lindstromhenrik You can convert MemoryCacheProvider to a version generic in TResult using

myMemoryCacheProvider.AsyncFor<TResult>
// or (for sync usage)
myMemoryCacheProvider.For<TResult>

as described in the MemoryCacheProvider documentation.

1reaction
lindstromhenrikcommented, Sep 16, 2019

As ResultTtl<TResult> : ITtlStrategy<TResult> and ITtlStrategy<TResult> does not extend ITtlStrategy it may be worth to point out that the cache provider need to implement IAsyncCacheProvider<TResult>, i.e it is incompatible with for example the MemoryCacheProvider.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic caching policy with Polly
If you just want to selectively cache for a specific response type, e.g. HttpResponseMessage , then that is actually not too difficult and...
Read more >
Selectively Caching a HttpResponseMessage with Polly
This article will demonstrate how to selectively cache HttpResponseMessages based on the Http StatusCode of the response.
Read more >
Caching
Using the advanced per-endpoint approach, you can selectively cache the responses to all requests, only those from specific paths or only responses with ......
Read more >
Selectively Caching Values Inside HttpResponseMessage ...
This final post will show how to selectively cache values inside the response based on the status of the response.
Read more >
HTTP caching - MDN Web Docs
The HTTP cache stores a response associated with a request and reuses the stored response for subsequent requests.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found