Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The behaviour you've described is correct <em>(<a href="http://nhibernate.hibernatingrhinos.com/28/first-and-second-level-caching-in-nhibernate">more here</a>)</em>. </p> <blockquote> <p>The update timestamp cache is not updated until you commit the transaction! This is to ensure that you will not read "uncommitted values" from the cache.</p> </blockquote> <p>Whenever there is a change on a <code>type</code> which we've got in Cache - cached data are stale... until the complete transaction is commited.</p> <p>Imagine that you've cached results of this filter:</p> <pre><code> var query = (from w in session.Query&lt;Widget&gt;().Cacheable() where w.Name == "B*" // all names starting with B select w); </code></pre> <p>And later will add new Widget:</p> <pre><code>var widget = new Widget {Name = "Brigitte"}; session.Save(widget); // explicit Flush is not needed, // but then, until Commit(), query will never return Brigitte session.Flush(); // to immediately execute INSERT </code></pre> <p>If the query would be still cached, Brigitte will never appear...</p> <p>And while in Transaction, queries with FirstOrDefault() are executed immediately - the write operations could wait for a Flush on Commit.</p> <p>Because of the Transaction, all contained operations (insert, udpate, select) cannot profit from caching, because only Transaction as a batch makes sense. So until commit is called, no cache could be used. </p> <p>Many detailed and very helpful information could be found here: <a href="http://nhibernate.hibernatingrhinos.com/28/first-and-second-level-caching-in-nhibernate">First and Second Level caching in NHibernate</a></p> <blockquote> <p>The timestamp cache is updated whenever a table is written to, but in a tricky sort of way:</p> <ul> <li>When we perform the actual writing, we write a value that is somewhere in the future to the cache. So all queries that hit the cache now will not find it, and then hit the DB to get the new data. Since we are in the middle of transaction, they would wait until we finish the transaction. If we are using low isolation level, and another thread / machine attempts to put the old results back in the cache, it wouldn't hold, because the update timestamp is into the future.</li> <li>When we perform the commit on the transaction, we update the timestamp cache with the current value.</li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload