开发者

How to clear NHibernate Cache on any exceptions

I have one NHibernate web application. I have used sys cache provider. While doing any transaction, due to any reason over communication problem between DB server or App server (E.g., n/w problem), the query will fail and this is obvious. But the issue is, this result i.e., exception, is cached for that query, the subsequent execution returns the same result.

The worse case is this happens even on versioning issue i.e., say while updating an domain entity, the same row was already updated by another transaction, the query execution gives an exception with message "Row was updated or deleted by another transaction". This result is cached for the period of default cache configuration time (5 mins).

How to configure not to cache the result on exception or how to cle开发者_运维知识库ar the cached result during this scenario?

Thanks for help.

Thanks and Regards,

Vijay Pandurangan


You can catch the exception that is thrown, then depending on the exception, evict the entity from the cache using ISession.Evict() (there are several overrides, and EvictCollection() exists too). To invalidate the whole cache, you can use ISession.Clear(). If you really don't trust it, I'd probably create a new ISession entirely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜