How to clear the entire second level cache in NHibernate

前端 未结 1 403
长发绾君心
长发绾君心 2020-12-23 14:53

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 us

相关标签:
1条回答
  • 2020-12-23 15:18

    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 讨论(0)
提交回复
热议问题