Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I totally disable caching in nHibernate?

Tags:

nhibernate

How do I totally disable caching in nHibernate?

like image 244
Larry Foulkrod Avatar asked Sep 22 '08 22:09

Larry Foulkrod


People also ask

How do I clear NHibernate cache?

NHibernate will evict associated entities automatically if the association is mapped with cascade="all" or cascade="all-delete-orphan". The ISession also provides a Contains() method to determine if an instance belongs to the session cache. To completely evict all objects from the session cache, call ISession. Clear().

How does NHibernate cache work?

An NHibernate session has an internal (first-level) cache where it keeps its entities. There is no sharing between these caches - a first-level cache belongs to a given session and is destroyed with it. NHibernate provides a second-level cache system; it works at the session factory level.


1 Answers

Use the IStatelessSession to bypass the first level cache: http://darioquintana.com.ar/blogging/?p=4

In order to use the second level cache you must explicitly configure it. You will not use it if you don't.

You can also turn off lazy loading in your mappings. lazy=false.

like image 115
Matt Hinze Avatar answered Oct 07 '22 21:10

Matt Hinze