Skip to content
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 local cache read to use before attempting a CAS operation #67

Open
dylanahsmith opened this issue Aug 19, 2021 · 2 comments
Open
Assignees

Comments

@dylanahsmith
Copy link
Contributor

cc @casperisfine

When using CAS to fill a cache entry, we want to read from the local cache to try to get a cache hit without going to the remote cache. With #66 the local cache is updated at the end of the CAS methods, but it isn't used for reading, which does make sense in other cases where we want to make sure the remote cache entry is updated to the correct value. We also can't seamlessly add local cache reading to the CAS methods, since the given block is also used to compute the updated value which can be expensive when involving database loads where we only want to do that after first reading from the remote cache.

Currently, Active Support doesn't support getting the local cache to read from directly. I also can't think of a good reason to use that with the methods Active Support supports, since it doesn't support CAS operations.

Adding support for local cache reads would avoid this problem and given the application flexibility in how it handles the local cache value. Currently, I don't see a need to expose local cache writes so I think we could avoid exposing the local cache object or encouraging the application to manage the updating of the local cache directly.

@dylanahsmith dylanahsmith self-assigned this Aug 19, 2021
@casperisfine
Copy link
Contributor

the local cache is updated at the end of the CAS methods, but it isn't used for reading

Hum, right, but that's because the read is mostly to get the CAS token. We'd need to store that one in the local cache too. I suppose it's doable.

@dylanahsmith
Copy link
Contributor Author

Although we could do a local cache read of the CAS token then do a remote CAS set, it could increase the chance of a cache conflict. Often the cache operation is the cheaper operation, so trying to save on a CAS get could increase the cache miss rate. Allowing a local cache read would provide more flexibility in what trade-offs are made so a local cache can be introduced without making performance worse.

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

No branches or pull requests

2 participants