简体   繁体   中英

infinispan hibernate 2nd level cache - XML Configuration format required

We are currently using ehcache as 2nd level cache with the following configuration in our application.

<!--  Configure 2nd level cacheing for these entities -->
<cache name="cacheEntity1"
    maxElementsInMemory="1500"
    eternal="true"
    overflowToDisk="false"/>
<cache name="cacheEntity2"
    maxElementsInMemory="3500"
    eternal="true"
    overflowToDisk="false"/>

We are planning to move to infinispan cache. By looking at the documentation of infinispan, we are not able to locate any XML configuration examples for defining cache entities similar to the one above using ehcache.

We are looking to configure the following attributes (maxInMemory, timeToIdleSeconds, timeToLiveSeconds ) at the hibernate entity level.

We prefer to do this configuration using XML rather than a programmatical way.

Any suggestion?

Reference - https://infinispan.org/docs/8.2.x/user_guide/user_guide.html#_using_infinispan_as_jpa_hibernate_second_level_cache_provider

Thanks,

Sadashiv

@Sada, for Infinispan Hibernate cache, I highly recommend you look at the simple tutorials we have here . They cover standalone, Spring and WildFly use cases. I'd start there.

Also, see the base configuration we use for cache configurations. LIRS is not in use, and it doesn't make sense to have a second level cache persisted to disk locally, it's just going to slow things down or consume extra resources unnecessarily.

I suggest you to configure a cache configured with an eviction strategy.

Eg. (inside your cache-container configuration)

      <local-cache name="cacheEntity1" >
         <eviction max-entries="1500" strategy="LIRS"/>
      </local-cache>
      <local-cache name="cacheEntity2" >
         <eviction max-entries="3500" strategy="LIRS"/>
      </local-cache>

If you wish to overflow entries to disk you can add to your local cache a persistence store.

Eg.

      <local-cache name="cacheEntityX" >
         <eviction max-entries="3500" strategy="LIRS"/>
         <persistence passivation="false">
            <file-store path="/mydata/FileCacheStore-LocationX" />
         </persistence>
      </local-cache>

Eviction is typically used in conjunction with a cache store (entries are not permanently lost when evicted). Eviction only removes entries from memory and not from cache stores. See infinispan docs

You can select a different eviction strategy (NONE, UNORDERED, LRU, LIRS, MANUAL). Take in mind that some strategies are deprecated in last Infinispan versions. eviction strategies

If you want attach lifespan and/or maximum idle times to entries, Expiration is your choice. expiration

Eg.

 <local-cache name="cacheEntityX" >
     <eviction max-entries="3500" strategy="LIRS"/>
     <expiration lifespan="1000" max-idle="500" interval="1000" />
     <persistence passivation="true">
        <file-store path="/mydata/FileCacheStore-LocationX" />
     </persistence>
  </local-cache>

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM