Jira/Java - injecting cache manager not working (setter)

Wiard van Rij May 8, 2017

I'm building a plugin for Jira. I want to add a caching-layer so I wanted to use the

com.atlassian.cache.CacheManager

 I have to inject this via an argument / setter.

Since I'm extending an other class I wanted to inject this via a setter, but for some reason it returns null all the time. It does not go past the setter.

import com.atlassian.cache.Cache;
import com.atlassian.cache.CacheLoader;
import com.atlassian.cache.CacheManager;
import com.atlassian.cache.CacheSettingsBuilder;

public class Foo extends AbstractJiraContextProvider
{
    private CacheManager cacheManager;

    public void setCacheManager(CacheManager cacheManager) {
        //It does not get past this function..
        this.cacheManager = cacheManager;
    }

    @Override
    public Map getContextMap(ApplicationUser user, JiraHelper jiraHelper) {


        cache = this.cacheManager.getCache("bar");

    }
}

I also tried this by doing the following:

public Foo(CacheManager cacheManager) {
    this.cacheManager = cacheManager;
}

After that the plugin does nothing anymore. I do not get errors, but it just gives 0 output.

I used this for documentation: https://developer.atlassian.com/confdev/confluence-plugin-guide/writing-confluence-plugins/accessing-confluence-components-from-plugin-modules

And https://developer.atlassian.com/confdev/development-resources/confluence-developer-faq/how-do-i-cache-data-in-a-plugin#HowdoIcachedatainaplugin?-Instructions

2 answers

1 accepted

0 votes
Answer accepted
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 9, 2017

Hi Wiard! This looks like a developer question, so my recommendation would be to ask our Developer Community for help. You can find them at community.developer.atlassian.com.

Cheers :)

Ana

Wiard van Rij May 9, 2017

Thank you Ana :) 

0 votes
Wiard van Rij May 9, 2017

For those who are interrested, I moved my question to here: https://community.developer.atlassian.com/t/injecting-cachemanager-not-working-setter/3574

Suggest an answer

Log in or Sign up to answer