简体   繁体   English

如何在NHibernate.Search中使用二级缓存

[英]How to use 2nd Level Cache with NHibernate.Search

How to use 2nd Level Cache with NHibernate.Search ? 如何在NHibernate.Search中使用二级缓存?

I tried to enable SetCacheable on FullTextQuery, but it doesn't work. 我试图在FullTextQuery上启用SetCacheable,但是它不起作用。

        var session = Search.CreateFullTextSession(database.Session);

        session.CacheMode = CacheMode.Normal;

        var textQuery = session.CreateFullTextQuery(query, new[] { typeof(Job) });

        textQuery.SetCacheable(true);
        textQuery.SetCacheRegion("Job");

        var jobs = textQuery.List<Job>();

        return jobs;

For all other standard queries tha cache works well but with FullTextQueries, it doesn't, NHibernate.Search still hit my database. 对于所有其他标准查询,NHibernate可以很好地使用缓存,但使用FullTextQueries则不能,NHibernate.Search仍然可以访问我的数据库。

Note that NHibernate.Search produced queries are SELECT ... WHERE EntityId IN (Id1,Id2,Id3,...) 请注意,NHibernate.Search生成的查询是SELECT ... WHERE EntityId IN(Id1,Id2,Id3,...)

are you sure that your entities are in the 2nd level cache. 您确定您的实体位于第二级缓存中。 Normally you have to be working and querying within transactions in order for the 2nd level cache to do anything. 通常,您必须在事务内进行工作和查询,才能使第二级缓存执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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