I’m trying to get plugins to share an Atlassian Cache but find that the experience does not bear out what the documentation states.
e.g. Atlassian Cache 2 overview (seriously out-of-date)
https://developer.atlassian.com/server/jira/platform/developing-for-high-availability-and-clustering/
private static final CacheSettings CACHE_SETTINGS = new CacheSettingsBuilder()
.remote()
.replicateViaInvalidation()
.expireAfterWrite(1, TimeUnit.DAYS)
.maxEntries(100)
.flushable()
.statisticsEnabled()
.build();
sharedCache = cacheManager.getCache(CACHE_KEY + "cache", null, CACHE_SETTINGS);
This creates a shared cache that works. i.e. one plugin can set or invalidate a cache entry and the others will be able to find the cached value.
But…
sharedCache = cacheManager.getCache(CACHE_KEY + "cache", new CacheLoader<String, String>() {
@Nonnull
@Override
public String load(@Nonnull String key) {
String value = ...<get data from plugin settings/>
if (value != null) {
return value;
} else {
return "";
}
}
}, CACHE_SETTINGS);
In this case, each plugin appears to have it’s own cache - each invokes the loader.
Now if one of the plugins updates the plugin settings and then removes or updates the cached value, then only that plugin sees the new value - the other plugins do not reinvoke their cache loader - in other words, the cache isn’t really shared, as invalidation of a cache entry is not propagated.
It seems to me that this means cache sharing is broken.