0

I want to set up a cache which does not expire in a SPring Boot EH Cache application. I want to reload cache based on a application parameter. How can i implement that? I can see there is a TimeToLiveinMinutes parameter. Should i increase the value for that , If yes how much maximum i can give a value to that. Please suggest.

Sajal Saxena
  • 191
  • 1
  • 3
  • 16

1 Answers1

0

If you don't specify a time to live, the entries won't expire. For example, entries in a cache with below config don't expire:

<config xmlns='http://www.ehcache.org/v3'
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">

    <cache alias="testCache">
        <resources>
            <heap unit="entries">100</heap>
            <offheap unit="MB">10</offheap>
        </resources>
    </cache> 
</config>

Whereas entries in a cache with below config expire every 10 seconds:


<config xmlns='http://www.ehcache.org/v3'
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">

    <cache alias="testCache">
        <expiry>
            <ttl unit="seconds">10</ttl>
        </expiry>

        <resources>
            <heap unit="entries">100</heap>
            <offheap unit="MB">10</offheap>
        </resources>
    </cache> 
</config>

You can find sample working applications for both the non-expiring and expiring caches on github.

devatherock
  • 2,423
  • 1
  • 8
  • 23