-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Cache miss on deserialization error in L2 cache #324
Comments
Hi @angularsen , this is a good one! In theory it would also help when there are wire format versioning updates. I have to think about it a little bit cause edge cases, potentially infinite update cycles and so on but... it may work! Will update. |
ps: right now I'm deep into Tagging which is uber complex and very delicate (and if you'd like to spend some time reading the proposal and sharing you think it would be really helpful), but I'll tackle this one right after that. |
Great! Yes, I would think it helps a lot. I just stumbled on the Tagging thread while posting this, and that also looks super interesting. Following closely, as I've struggled to find a good strategy to invalidate say all cache for a particular user, and your proposal looks like a real nice solution to that 👏 |
Hi @angularsen I was just re-reading this issue and I thought that I haven't mentioned setting Have you already tried it? |
@jodydonetti No I have not, and I'm not sure I understand how that would work based on the description. How can I use this to ignore or invalidate invalid JSON? Will it simply treat it as cache miss already, or will something else happen?
|
I may expand the docs a little bit, but yeah: with Now that I think about it though, it would be better to be able to differentiate between reads and writes: an error on read (deserialize) may be ignorable, but an error when writing would mean 99.999% of the times a bad configuration, which would not go away anyway unless fixed in code. Should I add 2 separate options maybe? Thoughts? |
Is there any usecase for not rethrowing on write serialization error? Not sure when anyone would ever want that. I see two options:
Either way, it's kind of a breaking change for both default options and for users explicitly configuring |
Well... I mean, I can't think of any right now 😑 Back when I added that option, I did so while also adding In fact there is already a difference between the first 2 and the last one: by default the first two are set to You know what? Probably I can just... (see below)
... this, I think it's the way to go.
Two things here:
And v2 is a major version, which allows for breaking changes (and I'm already making some, although hopefully backward compatible for 99.999% of the cases). So yeah I think we have a solution here. Agree? |
Sounds great to me 👍 |
Verified that setting Closing this as solved, although the solution we discussed still makes sense 👍 |
Awesome, happy you're unblocked now!
Yep, I'll create an issue to track that change and will include it in v2. |
Hi all, v2.0.0-preview-3 is out 🥳 |
Hi all, I still can't believe it but v2.0.0 is finally out 🎉 |
Problem
On a few occations I have accidentally broken cache deserialization by adding non-nullable properties to the DTO class for the cache entry, while existing entries in Redis are missing these. This mistake is easy to make, and it can effectively cause downtime for an API resource attempting to read the cache entry with
GetOrSet
semantics.Solution
FusionCacheEntryOptions.TreatDistributedCacheDeserializationErrorAsCacheMiss
, to treat it as cache missGetOrSet
, it will invoke the factory methodGet
, it will return no resultI first considered to evict the distributed cache entry, but I realize that may add a performance hit and it may be better to just treat it as a cache miss and only update the cache entry if the factory successfully produces a new fresh value.
Alternatives
Using Events to invalidate cache on deserialization error. However, this still results in one failed API request for each cache entry.
I want to achieve zero failed API requests if the cache entry is invalid for any reason, without having to try-catch everywhere or add my own extensions methods on top of
GetOrSet
.Additional context
None
I'm up for attempting a pull request on this, if that helps move this along.
The text was updated successfully, but these errors were encountered: