2011-04-07 59 views
3

我不想手动无效(刷新)二级缓存。我怎样才能做到这一点?NHibernate二级缓存手动无效

+1

重复:http://stackoverflow.com/questions/2985749/nhibernate-second-level-cache-with-external-updates的 – cbp 2011-04-07 02:11:55

+0

可能重复[如何在NHibernate中清除整个二级缓存](http://stackoverflow.com/questions/2660714/how-to-clear-the-entire-second-level-cache-in-nhibernate) – 2011-04-07 13:33:40

回答

4

你可以做这样的事情:

SessionFactory.EvictQueries(); 
foreach (var collectionMetadata in this._SessionFactory.GetAllCollectionMetadata()) 
     SessionFactory.EvictCollection(collectionMetadata.Key); 
foreach (var classMetadata in this._SessionFactory.GetAllClassMetadata()) 
     SessionFactory.EvictEntity(classMetadata.Key); 
+0

嘿,那就是* my *位! ;-) – 2011-04-07 13:34:34

+0

是的,我喜欢它:-)其实,我知道我从某人那里得到了它,但我不记得那是你的。 – LeftyX 2011-04-07 16:59:43