Infinispan - set per Entity expiration.lifespan

隐身守侯 提交于 2019-12-01 06:25:34

问题


I have a java web application deployed on Jboss 6.1.0, that uses infinispan 5.2.6.Final. I'm trying to set a per Entity specific expiration.lifespan following this guide

http://infinispan.org/docs/5.2.x/user_guide/user_guide.html#_advanced_configuration_2

for my Entity bean com.myenterprise.myproject.dal.ejb.entity.RefStatus.

The guide states the following:

You can also override eviction/expiration settings on a per entity/collection type basis in such way that the overriden settings only afftect that particular entity (i.e. com.acme.Person) or collection type (i.e. com.acme.Person.addresses). For example:

<property name="hibernate.cache.infinispan.com.acme.Person.expiration.lifespan" value= "65000"/>

So, i've added the following element to my persistence.xml, to reduce the lifespan to 10 milliseconds for test purposes, in order to fine tune it later:

<property name="hibernate.cache.infinispan.com.myenterprise.myproject.dal.ejb.entity.RefStatus.expiration.lifespan" value= "10"/>

The setting produces no effects and the lifespan remains the default.

Do you know how I have to set the persistence.xml to successfully override the default expiration lifespan? Setting the

<property name="hibernate.cache.infinispan.entity.expiration.lifespan" value= "10"/>

it works, but it affects all entity caches, and it is not what I want.

What follows is my application.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
    <persistence-unit name="myProject_dal_PU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/myProject-DataSource</jta-data-source>
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="false" />

            <property name="hibernate.cache.use_second_level_cache" value="true" />
            <property name="hibernate.cache.use_minimal_puts" value="true" />
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.cache.infinispan.com.myenterprise.myproject.dal.ejb.entity.RefStatus.expiration.lifespan" value= "10"/>
        </properties>
    </persistence-unit>
</persistence>

Thank you.


回答1:


If you are running within the application server, apart from the entity name, you have to provide the deployment name and unit too. So, all such expiration properties need to be prepended with: hibernate.cache.infinispan.<warname>.<unitname>.<FQN of entity>...

In your case, I don't know the name of your deployment, but with the unit and FQN that you mention, something like:

hibernate.cache.infinispan.<warname>.myProject_dal_PU.com.myenterprise.myproject.dal.ejb.entity.RefStatus.expiration.lifespan




回答2:


Spent hours to find correct configuration. Apparently it is as following:

Hibernate property should be in the following format:

hibernate.cache.infinispan.<prefix>.<full-class-name>.<property-name> where:

<prefix> - by default it is in the name that you see in a sort of JNDI name. In case of Wildfly, it is ear-name.ear/ejb-jar-name.jar#persistence-unit-name However, it can be controlled by hibernate.cache.region_prefix property. Set region_prefix to "" and ignore the prefix.

<property-name> - String as it appears in org.hibernate.cache.infinispan.InfinispanRegionFactory class and in official Infinispan documentation.

In short, official Infinispan documentation is correct only when you set hibernate.cache.region_prefix to ""



来源:https://stackoverflow.com/questions/24058913/infinispan-set-per-entity-expiration-lifespan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!