# Atlassian cache - plugin shared cache weird behaviour

**URL:** <https://community.developer.atlassian.com/t/atlassian-cache-plugin-shared-cache-weird-behaviour/41624>\
**Category:** Atlassian Developer Tools\
**Tags:** cache\
**Created:** [September 18, 2020, 9:09am UTC](https://community.developer.atlassian.com/t/atlassian-cache-plugin-shared-cache-weird-behaviour/41624 "2020-09-18T09:09:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pslootweg](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/pslootweg/32/46517_2.png) [@pslootweg](https://community.developer.atlassian.com/u/pslootweg)\
**Post date:** [September 18, 2020, 9:09am UTC](https://community.developer.atlassian.com/t/atlassian-cache-plugin-shared-cache-weird-behaviour/41624/1 "2020-09-18T09:09:25Z")

</div>

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](https://developer.atlassian.com/server/confluence/atlassian-cache-2-overview/) (seriously out-of-date)  
[https://developer.atlassian.com/server/jira/platform/developing-for-high-availability-and-clustering/](https://developer.atlassian.com/server/jira/platform/developing-for-high-availability-and-clustering/)

```auto
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…

```auto
        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.

---

<div class="post-metadata">

**Author:** ![danielwester](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/danielwester/32/36730_2.png) [@danielwester](https://community.developer.atlassian.com/u/danielwester)\
**Post date:** [September 18, 2020, 3:05pm UTC](https://community.developer.atlassian.com/t/atlassian-cache-plugin-shared-cache-weird-behaviour/41624/2 "2020-09-18T15:05:13Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![pslootweg](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/pslootweg/32/46517_2.png) [@pslootweg](https://community.developer.atlassian.com/u/pslootweg)\
**Post date:** [September 18, 2020, 3:14pm UTC](https://community.developer.atlassian.com/t/atlassian-cache-plugin-shared-cache-weird-behaviour/41624/3 "2020-09-18T15:14:26Z")

</div>

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?
