简体   繁体   English

SysCache2和FluentNhibernate在MVC应用中

[英]SysCache2 and FluentNhibernate on MVC aplication

I am having a problem with SysCache/SysCache2 on my MVC application. 我的MVC应用程序上的SysCache / SysCache2出现问题。 My configuration seems to be correct. 我的配置似乎是正确的。 I have set it up just like countless examples on the web. 我已经像网络上无数的示例一样进行了设置。

On my class I have put: Cache.Region("LongTerm").NonStrictReadWrite().IncludeAll(); 在我的课程中,我输入了: Cache.Region("LongTerm").NonStrictReadWrite().IncludeAll(); Here is a Test I made for the application cache. 这是我为应用程序缓存所做的测试。

[Test]
        public void cache()
        {
            using (var session = sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var acc = session.QueryOver<Log>().Cacheable().List();
                tx.Commit();
            }

            var test = sessionFactory.Statistics.SecondLevelCacheHitCount;

            using (var session = sessionFactory.OpenSession())
            {
                var acc = session.QueryOver<Log>().List();
            }

            var test1 = sessionFactory.Statistics.SecondLevelCacheHitCount;
        }

The first statement is cached as I see in the session factory statistics (for example 230 records). 正如我在会话工厂统计信息中所看到的那样,第一条语句被缓存了(例如230条记录)。 If i understand it right second statement that is below shouldnt hit the db but the Cache. 如果我理解正确的话,下面的第二条语句不应该命中数据库,而是缓存。 Problem here is that it goes to DB anyway. 这里的问题是无论如何都要去数据库。 Checked with profiler to be 100% sure. 与分析器一起检查是100%确定的。

I don't know what am I doing wrong here. 我不知道我在做什么错。 Anyone has an idea? 有人有主意吗?

I have managed to solve this problem. 我设法解决了这个问题。 It had to do with my session creation. 这与我的会话创建有关。 I didn't use session per request which triggered not going to cache. 我没有为每个请求使用会话,这触发了不进行缓存。 I created transaction on begining and it lasted through entire session. 我从一开始就创建了事务,并持续了整个会话。 I managed to trigger entering cache if i opened the session again within using mark like: using(var sess = session.SessionFactory.OpenSession()) but this solution was only a workaround which didn't suit me so I changed how I created sessions in the first place and it works fine now! 如果我再次使用以下标记打开会话,就设法触发了进入缓存的使用:using(var sess = session.SessionFactory.OpenSession()),但是此解决方案只是不适合我的解决方法,因此我更改了创建会话的方式首先,它现在可以正常工作! :) :)

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

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