Dynamically adding caches in SSMCacheManager

22 views
Skip to first unread message

Sweta Nahata

unread,
Jun 8, 2018, 7:23:25 AM6/8/18
to simple-spring-memecached
Hi,

1. Is there a way to dynamically add new caches in SSMCacheManager or it has to be set only when defining the SSMCacheManager bean in the caches property?

I am trying to add as a new cache dynamically in code as below
SSMCache ssmCache = new SSMCache(new PrefixedCacheImpl(cache,
getName(), NAME_PREFIX_SEPERATOR), timeToLive.intValue(),
true, false, true);
getCacheManager().getCaches().add(ssmCache);

However, by this way sSMCacheManager.getCacheNames() or sSMCacheManager.getCache(name) does not return the newly added cache?

2. Is there a way to dynamically modify the expiration of SSMCache?

Thanks,
Sweta


Jakub Białek

unread,
Jun 10, 2018, 4:07:35 PM6/10/18
to simple-spring-memecached
Hi,

To make it work you have to invoke protected method: CacheManager.addCache. CacheManager has two additional fields that keep it state: cacheName and cacheMap. Those fields have to be sync with result of CacheManager.getCaches().

It depends what dynamic means for you. The ExtendedSSMCacheManager allows to set expiration time on each method separately as a part definition in annotation.

Best regards,
Ragnor  

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-spring-memecached@googlegroups.com.
Visit this group at https://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

Sweta Nahata

unread,
Jun 11, 2018, 5:42:23 AM6/11/18
to simple-spring-memecached
Hi Ragnor,

Yes, saw this method but since this method CacheManager.addCache is protected we will not be able to access it using instance in a class which is in some other package than this one. Can we make it public? 
For now, I have solved it by extending the SSMCacheManager and exposing a public method for the same.

Regarding being able to modify the expiration of SSMCache dynamically, I wanted the capability to be able to modify the expiration in code and I found it by doing 
new SSMCache(cache, timeoutSeconds);

Thanks,
Sweta

On Monday, June 11, 2018 at 1:37:35 AM UTC+5:30, ragnor84 wrote:
Hi,

To make it work you have to invoke protected method: CacheManager.addCache. CacheManager has two additional fields that keep it state: cacheName and cacheMap. Those fields have to be sync with result of CacheManager.getCaches().

It depends what dynamic means for you. The ExtendedSSMCacheManager allows to set expiration time on each method separately as a part definition in annotation.

Best regards,
Ragnor  
On 8 June 2018 at 13:23, Sweta Nahata <naha...@gmail.com> wrote:
Hi,

1. Is there a way to dynamically add new caches in SSMCacheManager or it has to be set only when defining the SSMCacheManager bean in the caches property?

I am trying to add as a new cache dynamically in code as below
SSMCache ssmCache = new SSMCache(new PrefixedCacheImpl(cache,
getName(), NAME_PREFIX_SEPERATOR), timeToLive.intValue(),
true, false, true);
getCacheManager().getCaches().add(ssmCache);

However, by this way sSMCacheManager.getCacheNames() or sSMCacheManager.getCache(name) does not return the newly added cache?

2. Is there a way to dynamically modify the expiration of SSMCache?

Thanks,
Sweta


--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.

Jakub Białek

unread,
Jun 11, 2018, 8:55:05 AM6/11/18
to simple-spring-memecached
Hi,

Could you please create a feature request (issue) on github to make addCache public?

Best regards,
Ragnor

To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsubscr...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at https://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-spring-memecached@googlegroups.com.

Sweta Nahata

unread,
Jun 11, 2018, 9:04:27 AM6/11/18
to simple-spring-memecached
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at https://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages