I’m using this client in my Spring boot
project to connect to my memcached
instance running on my cluster.
Everything works fine BUT so far I could only set on expiration date for all my caches, which is not convenient for me now, I want to able to set custom expiration dates like it’s possible to do on memcached
for Appengine
.
Anybody has any idea? the client doesn’t seem that flexible.
2
Answers
This is because Spring does not have native support for custom expiration. I suggest you use
simple-spring-memcached
with Spring Boot to enable custom expiration. If you use this library you have two options:simple-spring-memcached
. They support custom expiration.Use the
ExtendedSSMCacheManager
provided bysimple-spring-memcached
to integrate with Spring Boot’s native caching. It allows you to set expiration as part of the cache name like so:Here
default
is the cache name and the expiration is set to 3600 seconds.For more information on how to set up
simple-spring-memcached
with Spring Boot see the SSM wiki or MemCachier’s Spring Boot documentation.For step by step instructions on how to use
simple-spring-memcached
with Spring Boot see this tutorial. It is created for the Heroku platform but works independently from Heroku.You could set custom expiration per cache name also with memcached-spring-boot library. You can just do it through
memcached.cache.expirations
configuration property. E.g.:Here
86400
represents global expiration (used for all caches). And in case you want to have different expiration value per cache, you can set it up ascache_name1:3600
(cache with namecache_name1
will expire in3600
seconds).In this case your cache configuration is outside the source code, so it would be easier for you to configure different expiration per different environment (e.g. dev, prod).