-
Notifications
You must be signed in to change notification settings - Fork 50
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
Remove "object cache" misfeature; add simpler "resource cache" #708
Conversation
A server side data cache, use case (1), is still of interest, but should be explored in future issues and PRs. The primary goal of this PR is to remove the object cache in preparation for a beta release, and to put in place a way to do basic file handle caching, which we know can be important, to avoid thrashing file handles when serving a burst of parallel requests. |
One more interactive test. If the cache is zeroed out, the file is reopened on each request, as expected:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the mechanics of with_resource_cache
, and how it simplifies the code overall. Just a few notes from me; nothing major.
Co-authored-by: Eugene <ymatviych@bnl.gov>
The "object cache" was a misfeature because it mixed two distinct resource pools:
(1) Caching chunks of data
(2) Caching file handles
(I admit this should have been immediately clear at the time it was added. This was very early on when we were prototyping a lot of aspects to validate the general idea.)
This PR removes the "object cache" entirely. The only remaining mention is in the service configuration, where
object_cache
is still accepted, for backward-compatibility, but a warning is emitted that any configuration here has no effect:Then the PR adds in its place a "resource cache" which:
cachetools.TLRUCache
to do the heavy liftingHere we can see it in action. The file is only opened while processing the first request. The second request uses a cached file handle.
This is the relevant output. (Some noise related to #663 has been removed for clarity.)
After waiting for the cache expiry time (default 60 seconds) accessing it again opens the file again, as expected.
The cache parameters are tunable via environment variables, but this is intentionally not exposed through the service configuration or CLI. I think it's possible that we can choose sensible defaults that will not need to be overridden except in debugging scenarios.
Closes #683