-1

I'm using ehcache 3.0 and the latest version of Apache camel. I'd like to delete the element from cache after 120 seconds.

Following is the piece of code I'm using to achieve the same

        <setHeader headerName="CamelCacheOperation" id="setCamelEhCacheOperation001">
            <constant>CamelCacheAdd</constant>
        </setHeader>
        <setHeader headerName="CamelCacheTimeToLive" id="setCamelCacheTimeToLive001">
            <simple resultType="java.lang.Integer">120</simple>
        </setHeader>
        <setHeader headerName="CamelCacheTimeToIdle" id="setCamelCacheTimeToIdle001">
           <simple resultType="java.lang.Integer">120</simple>
        </setHeader> 
        <setHeader headerName="CamelCacheEternal" id="setCamelCacheEternal001">
            <simple resultType="java.lang.Integer">0</simple>
        </setHeader>
        <setHeader headerName="CamelEhcacheAction" id="setCamelEhCacheAction001">
            <constant>PUT</constant>
        </setHeader>
        <setHeader headerName="CamelEhCacheKey" id="setCamelEhCacheAction001">
            <simple resultType="java.lang.String">${property[cachekey]}</simple>
        </setHeader> 
       <setHeader headerName="CamelEhcacheValue" id="setCamelEhCacheValue001">
                <simple>${body}</simple>
        </setHeader>            
        <to id="putValueToEhCache" uri="ehcache://cache1?keyType=java.lang.String&amp;valueType=java.lang.String"/>

Even after the TTL duration the element is staying in cache. I've been using this as a reference : https://camel.apache.org/cache.html I've been stuck on this for a while now. Thanks in advance.

Rakhi Oza
  • 75
  • 1
  • 8

1 Answers1

2

CamelCacheTimeToLive is for the old camel-cache component, the new one, camel-ehcache does not handle such header.

To configure cache expiration you need to set-up a custom configuration as explained http://www.ehcache.org/documentation/3.7/expiry.html

Luca Burgazzoli
  • 1,216
  • 7
  • 9
  • Thanks for your response. Is there any other way to pass on the expiry through header or through ehcache uri itself, without explicitly writing ehcache.xml? – Rakhi Oza Apr 08 '19 at 10:38
  • My intention is avoiding ehcahe.xml file and try achieving this using some bean config in the camel-context.xml itself – Rakhi Oza Apr 08 '19 at 10:46
  • It is not possible using headers as ehcache 3.x does not expose such option so you need either to configure the ehcache component or endpoint, see https://github.com/apache/camel/blob/master/components/camel-ehcache/src/main/docs/ehcache-component.adoc As you are using xml already, writing xml may be the simpler option – Luca Burgazzoli Apr 09 '19 at 07:35