How to set Redis Cache expiration to 1 year?
I tried to set the long
value on the xml configuration to : 31556952000
(1 year), but then it caught an exception that type Integer doesn't recognize the value as Integer. I tried to search at Google, and it says that Integer maximum value is up to 2147483647
, which means, if I set to that maximum value, I only get my cache expires on 24 days.
Here is my applicationContext.xml
(I omitted unnecessary code) :
...
<cache:annotation-driven />
<bean id="redisCacheMap" class="java.util.HashMap">
<constructor-arg index="0" type="java.util.Map">
<map key-type="java.lang.String" value-type="java.lang.Integer">
<entry key="ruleCache" value="86400"/>
</map>
</constructor-arg>
</bean>
...
The code above is configured to set the expiration of ruleCache
to only 1 day (86400 in ms).
Is it possible to do that? Thanks.
Redis accepts integer value (maximum is up to 2 147 483 647) for expire command. The unit is second, not ms, so 1 year is 31556952 instead of 31556952000, and it fits into integer.
If you want your map to access Long, maybe you can adapt your config:
<map key-type="java.lang.String" value-type="java.lang.Long">