Skip to content

Commit

Permalink
Merge pull request #902 from okauppinen/cache-clustered-flush
Browse files Browse the repository at this point in the history
Cache clustered flush
  • Loading branch information
ZakarFin authored Dec 15, 2022
2 parents ae7c5a0 + 89af8b8 commit 93dfce7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion service-base/src/main/java/fi/nls/oskari/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public boolean put(final String name, final T item) {
}

public boolean flush(final boolean force) {
notifyFlush();
return flushSilent(force);
}

protected boolean flushSilent(final boolean force) {
final long now = currentTime();
if(force || isTimeToFlush(now)) {
// flushCache
Expand Down Expand Up @@ -203,7 +208,7 @@ protected void handleClusterMsg(String data) {
return;
}
if (CLUSTER_CMD_FLUSH.equals(data)) {
flush(true);
flushSilent(true);
return;
}
if (data.startsWith(CLUSTER_CMD_REMOVE_PREFIX)) {
Expand All @@ -217,6 +222,9 @@ protected void handleClusterMsg(String data) {
private void notifyRemoval(String key) {
notifyCluster(CLUSTER_CMD_REMOVE_PREFIX + key);
}
private void notifyFlush() {
notifyCluster(CLUSTER_CMD_FLUSH);
}

private void notifyCluster(String msg) {
if (!ClusterManager.isClustered()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public void testClusterMsgFromOthersFlush() {
// another cache instance
cache.handleClusterMsg(Cache.CLUSTER_CMD_FLUSH);
// message from OTHER should trigger call
Mockito.verify(cache).flush(true);
Mockito.verify(cache).flushSilent(true);
// but not trigger another notify for cluster
Mockito.verify(cache, never()).flush(true);
}

@Test
Expand Down

0 comments on commit 93dfce7

Please sign in to comment.