Expiring Cache
719736Aug 27 2009 — edited Aug 28 2009I'm new to Coherence. Was trying to get the cache expiry working for me but the code I have pasted below doesn't expire the cache automatically.
I am looking at using coherence cache as a mechanism to cache the response of my web-service for a specific interval during which the web-service can re-use the response from the cache. If the cache is expired, the web-service re-creates and re-fetches the response and after sending the response to the requester adds it to the coherence cache by specifying an expiry time.
Basically I am looking at coherence to expire the cache automatically and give me null data if the cache is expired. Re-filling or refreshing of data, I am planning it to be triggered by the calling web-service.
I'm using NamedCache.
Sample Code:
testPutAction:
NamedCache theCache = CacheFactory.getCache("dist-Cache");
theCache.put("Method1_R032", "TestData" , System.currentTimeMillis() + 10);
testGetAction
(String)theCache.get("Method1_R032")
The coherence-cache-config.xml I am using:
<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>dist-Cache</cache-name>
<scheme-name>distributed-cache-scheme</scheme-name>
<init-params>
<init-param>
<param-name>back-size-limit</param-name>
<param-value>8MB</param-value>
</init-param>
</init-params>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<!--
Distributed caching scheme.
-->
<distributed-scheme>
<scheme-name>distributed-cache-scheme</scheme-name>
<service-name>DistributedCache</service-name>
<expiry-delay>1</expiry-delay>
<autostart>true</autostart>
<backing-map-scheme>
<local-scheme>
</local-scheme>
</backing-map-scheme>
</distributed-scheme>
</caching-schemes>
</cache-config>