Hello!
We have a script rest endpoint that each time that it's called get an information from an external database.
We would like to cache this function since that multiple times the result query returns the same value.
Looking in the internet we have found someways with Guava framework (https://github.com/google/guava) but we would like your help to see if is there any example to this need.
What do you recommend ?
Thanks!
Have you tried to use build-in JIRA Cache functions? https://developer.atlassian.com/confdev/development-resources/confluence-developer-faq/how-do-i-cache-data-in-a-plugin
Not yet, this looks promissor. I'll give it a try!
@Gregor Kasmann_Actonic,
I'm trying to to use the provided document.
It seems that each time that I call CacheManager.getCache function the cache is erased and created a new one.
I'm testing using the Script Console (feature of Scriptrunner)
import com.atlassian.cache.Cache;import com.atlassian.cache.CacheLoader;import com.atlassian.cache.CacheManager;import com.atlassian.cache.CacheSettingsBuilder;import com.atlassian.util.concurrent.NotNull;import com.atlassian.cache.CacheSettings;import java.util.concurrent.TimeUnit;import com.atlassian.jira.component.ComponentAccessor;def CacheManager cacheManager = ComponentAccessor.getComponent(CacheManager.class);def cache = cacheManager.getCache("com.foo.test.cache", new ListPagesCacheLoader(), new CacheSettingsBuilder().expireAfterAccess(5, TimeUnit.MINUTES as TimeUnit).build());log.error cache.getKeys()cache.get("hi")log.error cache.getKeys()cache.get("hi")log.error cache.getKeys()public class ListPagesCacheLoader implements CacheLoader<String, String> {@Override public String load(@NotNull String value){ sleep(3000); return value; }}
It seems that the cache is being recreated each time that I call CacheManager#getCache.
We need this cache stored in disk or memory to each time that the rest endpoint be called we still have the keys into it.
Do you have any tip ?
It looks like you're new here. Sign in or register to get started.