NHibernate二级缓存,带有外部更新 [英] NHibernate second-level cache with external updates
问题描述
我有一个Web应用程序,该应用程序是99%只读的,具有一个单独的服务,该服务以特定的时间间隔(例如每10分钟更新一次)来更新数据库.该服务如何告知应用程序使其二级缓存无效?真的重要吗? (我实际上并不在乎是否有过时的数据)如果我不使高速缓存无效,则需要多长时间才能更新记录(如果使用SysCache)
I've got a web application that is 99% read-only, with a separate service that updates the database at specific intervals (like every 10 minutes). How can this service tell the application to invalidate it's second-level cache? Is it actually important? (I don't actually care if I have too much stale data) If I don't invalidate the cache how much time is needed to the records to get updated (if using SysCache)
推荐答案
您可以为特定实体,实体类型或集合手动设置二级缓存.
You can manually dispose your 2nd level cache for a specific entity, entity type or a collection.
来自 http://knol .google.com/k/fabio-maulo/nhibernate-chapter-16-improving/1nr4enxv3dpeq/19#
对于二级缓存,在ISessionFactory上定义了一些方法,用于清除实例,整个类,集合实例或整个集合角色的缓存状态.
For the second-level cache, there are methods defined on ISessionFactory for evicting the cached state of an instance, entire class, collection instance or entire collection role.
sessionFactory.Evict(typeof(Cat), catId); //evict a particular Cat
sessionFactory.Evict(typeof(Cat)); //evict all Cats
sessionFactory.EvictCollection("Eg.Cat.Kittens", catId); //evict a particular collection of kittens
sessionFactory.EvictCollection("Eg.Cat.Kittens"); //evict all kitten collections
这篇关于NHibernate二级缓存,带有外部更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!