我遇到了一个明显的缓存问题,NHibernate 返回的内容与数据库中的内容不匹配。
我相信这是二级缓存数据。看起来我可以使用 Evict 来做到这一点,但是什么时候应该实际调用 Evict 方法?对于我的特定应用程序,数据对于用户来说是唯一的,并且提供的数据很可能只会使用一次*。
我可以完全禁用这些对象集的二级缓存吗?
更新 10/31
我的场景是这样的:我有一个购物车,客户将在其中添加和删除商品。我正在做的事情如下:在处理购物车的更新之前,我逐出Cart
and CartProduct
实体。完成此操作后,我检索列表CartProducts
来自提供者并返回视图(这发生在 .NET MVC 控制器中)。
更新11/3
购物车已经完成了,我遇到了一个似乎与同一个 NHibernate 问题相关的问题,但实际上是一个 MVC 问题。更深入的挖掘表明,HTML Helper 扩展覆盖了我假设的值,并替换为模型状态中的值。所以这对我来说是双重打击。希望这对某人有帮助。
不可以,您无法禁用某些实体的缓存。
您确实有多种选择:
- Use ISession.Clear() to clear all entities from NHibernate's cache.
- http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache
- Use ISession.Evict( obj ) to clear a specific entity from the cache.
- http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache
- Use ISessionFactory.Evict( typeof( obj ) ) to evict all entities/objects of a particular type from the cache. This would be the closest to what you are wanting in my opinion.
- http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache http://nhibernate.info/doc/nh/en/index.html#performance-sessioncache
- Use the IStatelessSession to fetch the objects/entities from the database as this completely bypasses all caches.
- http://nhibernate.info/doc/nh/en/index.html#batch-statelesssession http://nhibernate.info/doc/nh/en/index.html#batch-statelesssession
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)