开发者

How to clear the entire second level cache in NHibernate

开发者 https://www.devze.com 2022-12-27 01:36 出处:网络
I wish to clear the entire second level cache in NHibernate via code.Is there a way to do this which is independe开发者_StackOverflow社区nt of the cache provider being used? (we have customers using b

I wish to clear the entire second level cache in NHibernate via code. Is there a way to do this which is independe开发者_StackOverflow社区nt 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).


This should do:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号