-
Notifications
You must be signed in to change notification settings - Fork 327
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
Implement reload cache clearing for CloudRequestCache
#12526
Conversation
@@ -61,6 +69,8 @@ public void cleanExpiredEntries() { | |||
} | |||
|
|||
public void put(String key, Value value, Duration ttl) { | |||
ReloadDetector.INSTANCE.clearOnReloadIfRegistered(this); |
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'm wondering if it could be worth it to encapsulate this piece of code into a method, so that we keep it in one place in case the method call pattern changes. But perhaps unnecessary.
private void checkReload() {
ReloadDetector.INSTANCE.clearOnReloadIfRegistered(this);
}
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've simplified this by making ReloadDetector
static and removing INSTANCE
, since it's not necessary.
@@ -84,6 +81,7 @@ public LRUCache(LRUCacheSettings settings, NowGetter nowGetter, DiskSpaceGetter | |||
this.settings = settings; | |||
this.nowGetter = nowGetter; | |||
this.diskSpaceGetter = diskSpaceGetter; | |||
ReloadDetector.INSTANCE.register(this); |
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.
The APIRequestCache
seems to not have this register
call. Is that by design or omission?
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.
Oh now I noticed - the base class does not have it but the implementation CloudRequestCache
does. Ok.
I'd suggest to add a note in the APIRequestCache
doc comment mentioning that implementations should call register
.
Or perhaps couldn't we make the APIRequestCache
call it in its constructor? So that implementations call it automatically. I'm worried someone creating a new implementation may easily forget this call so ideally I'd like to structure the code in such a way that it is hard to forget it :)
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 wanted to allow subclasses to decide if they want to use ReloadDetector
, so I've just added some documentation to APIRequestCache
.
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.
Ah ok, I thought that it would fail with the 'not registered exception' but didn't notice you have clearOnReloadIfNotRegistered
so it checks the registration.
Makes sense now, thanks for clarifying! And the note in the docs is appreciated.
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.
Overall changes look very good.
Just one nitpick if we can try to make APIRequestCache
easier to not-forget registering. But feel free to ignore if not as easy as I thought.
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.
Looks alright minus some potential race-conditions
Pull Request Description
This also refactors
ReloadDetector
to reduce the boilerplate needed to implement reload-triggered cache clearing.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.