Atlassian cache - plugin shared cache weird behaviour

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. (seriously out-of-date)

private static final CacheSettings CACHE_SETTINGS = new CacheSettingsBuilder()
            .expireAfterWrite(1, TimeUnit.DAYS)

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.


        sharedCache = cacheManager.getCache(CACHE_KEY + "cache", new CacheLoader<String, String>() {
            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.

You should probably have one plugin that owns the cache and then export the services from it to the others. If you have everyone writing to the same cache directly - that would be asking for trouble. Especially if you then start adding in DataCenter into the mix where there is the possibility of different versions of apps running on nodes (or not at all on some).

There is no documentation to direct me to do that - in fact quite the opposite.
In any case what if I uninstall the plugin that ‘owns’ the cache - what’s going to happen to the other plugins?

1 Like