For HybridCache, should it possible to do a Get from the cache and then do a Set separately? #57191
Unanswered
abhisheksaraiya
asked this question in
Q&A
Replies: 2 comments 4 replies
-
Seems like it is possible this way using
But in some cases, it would be nice to allow the tags be passed somehow by the factory function. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I was thinking the same thing. My use case was not to retrieve a value from the cache but just to know if it's there or not. I have these extension methods. Maybe they'd help you?
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So far, there is a method
GetOrCreateAsync
which takes in a factory and caches the item fetched by the factory if it isnt present in the cache.But there doesnt seem to be support for doing just a Get and then deciding if a Set should be called or not based upon the condition of the item to be cached.
What i mean is that if the requirement is that a null value should not be cached then one could do so:
This way I can Set data in cache only if they actually exist.
Also, this allows me to set tags which are part of the data itself.
The current signature of GetOrCreateAsync does not allow providing tags which might be part of the data fetched from the factory.
Am i missing something here or its part of the design?
Or is there a way to
I know that there is a chance for stampede during cache invalidation if set is done like this but since there isnt support within the existing
GetOrCreateAsync
perhaps doing a Get and Set separately is an option.Beta Was this translation helpful? Give feedback.
All reactions