How to clear the entire second level cache in NHibernate

帅比萌擦擦* 提交于 2019-12-18 10:19:57

问题


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).


回答1:


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);


来源:https://stackoverflow.com/questions/2660714/how-to-clear-the-entire-second-level-cache-in-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!