[英]How to find stale Infinispan / Jboss Cache objects?
Subject is the question. 主题是问题。
Scenario : Even though there is a logout link, some Users don't properly logout. 方案:即使存在注销链接,某些用户也无法正确注销。 And they immediately take a new tab and login again.
然后,他们立即选择一个新标签并再次登录。 This time a new Cache object is created and the old one is not getting destroyed.
这次将创建一个新的Cache对象,而旧的Cache对象不会被销毁。
First, you can set a default lifespan
or maxIdle
to make all entities time out so they don't stay stale for long. 首先,您可以设置默认
lifespan
或maxIdle
以使所有实体都超时,以使它们不会长时间保持陈旧。
However, to answer your question... You can use the infinispan-query
module: 但是,要回答您的问题...您可以使用
infinispan-query
模块:
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-query</artifactId>
<version>5.2.1.Final</version>
</dependency>
This uses hibernate search along with apache lucene to query your infinispan cache. 它使用休眠搜索和Apache Lucene来查询您的infinispan缓存。
To use this you need to annotate the fields you will search for with @org.hibernate.search.annotations.Field
and the class with @org.hibernate.search.annotations.Indexed
. 要使用此,你需要注释,你会与搜索领域
@org.hibernate.search.annotations.Field
并与类@org.hibernate.search.annotations.Indexed
。
Your infinispan cache will also need to be indexed <indexing enabled="true" indexLocalOnly="false" />
(local or distributed -- see the indexLocalOnly
property). 您的infinispan缓存也需要索引
<indexing enabled="true" indexLocalOnly="false" />
(本地或分布式-请参见indexLocalOnly
属性)。
And then you can query your cache with something like the following: 然后,您可以使用以下内容查询缓存:
import org.apache.lucene.search.Query;
import org.hibernate.search.query.dsl.QueryBuilder;
import org.infinispan.Cache;
import org.infinispan.query.CacheQuery;
import org.infinispan.query.Search;
import org.infinispan.query.SearchManager;
[...]
public List<YourEntity> searchEntities( String fieldValue ) {
SearchManager searchManager = Search.getSearchManager( cache );
QueryBuilder queryBuilder = searchManager.buildQueryBuilderForClass( YourEntity.class ).get();
// this chain will change depending on what you are querying
Query luceneQuery = queryBuilder.keyword().onField( "fieldName" ).matching( fieldValue ).createQuery();
// use either searchManager.getClusteredQuery with local index, or a searchManager.getQuery with clustered index
CacheQuery cacheQuery = searchManager.getQuery( luceneQuery, YourEntity.class );
//noinspection unchecked
return (List)cacheQuery.list();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.