Skip to content

Draft: Reset Caches by flushing DB#3314

Draft
christophstrobl wants to merge 2 commits intomainfrom
issue/3290
Draft

Draft: Reset Caches by flushing DB#3314
christophstrobl wants to merge 2 commits intomainfrom
issue/3290

Conversation

@christophstrobl
Copy link
Member

No description provided.

Copy link
Contributor

@onobc onobc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @christophstrobl . I have added some comments / questions.

/**
* @author Christoph Strobl
*/
interface CacheWriterOperation<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a @FunctionalInterface.

/**
* @author Christoph Strobl
*/
public abstract class ResetCachesStrategies {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may read better as CacheResetStrategy/ies - wdyt?

Uggh, naming... always hard.


private <T> T execute(String name, Function<RedisConnection, T> callback) {
@Override
public <T> T execute(Function<RedisConnection, T> callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure this will clear up w/ javadocs once we get firm on the direction, but it is currently not clear that the newly added execute method does not do the potential wait for unlocked (i.e. checkAndPotentiallyWaitUntilUnlocked).

return execute(null, callback);
}

private <T> T execute(@Nullable String name, Function<RedisConnection, T> callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just call executeLockFree instead of adding the @Nullable here.

@Override
public void resetCaches() {

if(resetCachesStrategy instanceof CacheWriterOperation<?> operation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought was to abstract the impl down into the strategy via a resetCaches method on the strategy where the strategy could take in a cache writer and a cache manager. The flushing variant could use the cache writer and the default variant could use the CM resetCaches impl. However, the latter would call back into CacheManager.resetCaches and that would infinite recurse (i.e. not get to super.resetCaches).

Just putting my thoughts - I am not sure which direction to go but I do like the thought of the strategy handling the work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure I am missing something, but it seems that we are overlapping w/ current cache cleaning impl in BatchStrategy (keys and scan). Seems like we could just add another strategy for flushAsync().

@Override
public String doWithCacheWriter(RedisCacheWriter cacheWriter) {
return cacheWriter.execute(connection -> {
connection.serverCommands().flushDb(FlushOption.ASYNC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other cleanup / stats we are missing that the super.resetCaches may be doing that we should do here as well?

/**
* @author Christoph Strobl
*/
public abstract class ResetCachesStrategies {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just ResetStrategy? Cache defines clear and evict methods and reset is distinct from these (thus it ranges semantically in a similar space).

Design-wise, it could be an interface with two static methods, sequential() (the default) and flushDb(). I like the CacheWriterOperation approach as it repeats how we approach functional composition in other parts of the framework.

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

Successfully merging this pull request may close these issues.

4 participants