-
Notifications
You must be signed in to change notification settings - Fork 174
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
Support temporarily disabling persisting nils for a model #501
Comments
First of all, we should probably have a way to completely opt-out of I suspect that would be good enough for your use case as well.
If Identity Cache is loading from the database using the default scope, then the row would be filtered in the database, so it wouldn't even see a idc_do_not_cache_nil column. Fundamentally, the database query itself would need to change, which also means that the default scope could no longer be used unchanged. Changing the default scope just for this caching concern doesn't seem appropriate. Also, using a separate scope for IdentityCache so that it can gets these rows and filter them in memory seems like it could interfere with the desired coupling to the default scope's semantics about what gets returned. Also, if Identity Cache is going to have to load the records and do filtering in-memory, then it would already have the values that the proposed
I don't see how this issue is in any way related to that. Cache fetching uses the CAS/ADD cache operations already to handle race conditions around cache fills even without that and the decision about whether or not to cache something loaded from the database just effects the decision about whether or not to fill the cache using one of those cache operations. |
My apologies, I made a mistake in my proposal wording. The goal was to persist an
I think this would probably work too. I can look into measuring the impact (basically the number of requests per day etc for this model that should return 404s).
I can definitely look into this again, but my recollection was that we didn't use CAS when it didn't exist in the cache in the first place. |
The special value for caching The special value for delete is on cache invalidation in order to invalidate any concurrent cache fills with old data. Semantically, it is treated as if the cache isn't filled. However, in this case we can just not fill the cache when the record is in this state. This is only detected on a cache miss, when the cache is already not filled, so we can just leave it in that state.
Right, because CAS only works for updating an existing value, so we use ADD to fill the cache in this case, which will also be invalidated by writing the special delete value |
Background
We have an odd scenario where we have a model with a default scope.
This enables us to hide this model from the rest of the system by default until it has reached
:success
.Due to system complexity sometimes a request can come for this record while it is in
:in_progress
state, which will cause IDC to cache anil
value. For us, cachingnil
is a good thing if the model is in:failed
state or if the record is on another shard (good performance characteristics) but not in:in_progress
state which means the record is inaccessible untilcache_ttl
Proposal
Add another flag that can be persisted to the db for a record called
idc_do_not_cache_nil
. Internally IDC will load this value and attempt to load from the db. In this scenario there are two possibilities:nil
- the default scope couldn't find the record (either:in_progress
,:failed
or simply not there) - return thenil
to the client but do not cache.The max time
idc_do_not_cache_nil
is present could becache_ttl
or it could be shorter in our case.This solves the exact problem we're encountering without introducing locking similar to the Thundering Herd problem: (#373).
The text was updated successfully, but these errors were encountered: