Simple Spring Memcached - how to add objects without any expiration

784 Views Asked by At

I am using SSMCache to store some objects in my application. I am adding the SSMCache object to my CacheManager like below :

@Bean
@Override
public CacheManager cacheManager() {
    Set<SSMCache> ssmCacheSet = new HashSet<>();
    try {
        ssmCacheSet.add(new SSMCache(getMyCache(),
                PropertyManager.getIntProperty("memcached.interval", 14400), true));
    } catch (Exception e) {
        LOGGER.error("Error creating cache manager", e);
    }

    SSMCacheManager ssmCacheManager = new SSMCacheManager();
    ssmCacheManager.setCaches(ssmCacheSet);
    return ssmCacheManager;
}

I want to know how to NOT specify the cache expiration time in order to make my cache available at all times ie. I do not want my cache to expire at all.

I went through the official documentation for Simple Spring Memcached but could not find on how to specify the value for a non expiring cache.

I think using a value of 0 will make the cache not expire at all, but I just want to make sure from a documentation or wiki where it is specified. Also I went through the constructors of SSMCache and could not find one which does not have expiration parameter.

Please help me on how to create the cache without an expiration time.

2

There are 2 best solutions below

0
On

Did you check the source code in Github repository. You can search "never expire" keyword in repository and you will get the files having lines like below. For example UpdateSingleCache.java has following detail in comments.

Also note: a value of 0 means the given value should never expire. The value is still susceptible to purging by memcached for space and LRU (least recently used) considerations.

0
On

Yes, 0 should notify memcached to not expire this key. This doesn't mean that the key will be forever in cache because it still can be removed from cache due to eviction.

If you notice that SSM does not honor 0 please report a bug.