如何清除NHibernate中的整个二级缓存 [英] How to clear the entire second level cache in NHibernate

查看:169
本文介绍了如何清除NHibernate中的整个二级缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过代码清除NHibernate中的整个二级缓存.有没有一种方法可以独立于所使用的缓存提供程序来执行此操作? (我们有客户在同一应用程序中同时使用内存缓存和syscache).

I wish to clear the entire second level cache in NHibernate via code. Is there a way to do this which is independent of the cache provider being used? (we have customers using both memcache and syscache within the same application).

我们希望清除整个缓存,因为可能发生了数据库外部的更改(并且我们不能保证:受影响的表/实体,因此我们必须假设最坏的情况).

We wish to clear the entire cache because of changes external to the database may have occurred (and we have no guarantees re: which tables/entities were affected, so we have to assume the worst).

推荐答案

这应该做到:

sessionFactory.EvictQueries();
foreach (var collectionMetadata in sessionFactory.GetAllCollectionMetadata())
         sessionFactory.EvictCollection(collectionMetadata.Key);
foreach (var classMetadata in sessionFactory.GetAllClassMetadata())
         sessionFactory.EvictEntity(classMetadata.Key);

这篇关于如何清除NHibernate中的整个二级缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆