views:

504

answers:

1

How can I configure NHibernate to not cache a file. I know I can create a method that does an HSQL, but can I through a configuration setting in the .xml file or the hibernate xml file itself to not cache a property?

Thanks in advance.

+1  A: 

You cannot set secondary caching settings at property level (as far as I know), but you can individually tune cache settings for each entity directly in their XML files.

For instance:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">  

<class name="ClassName" table="Table">
   <cache usage="nonstrict-read-write" />

    <id name="Id" type="Int64" ...

Where the cache "usage" property can be any of the following values:

  • read-write: assures read committed isolation, makes sure data is consistent but doesn't reduce DB access as much as the other modes,
  • nonstrict-read-write: objects with rare writes, slight chance of inconsistency between DB and cache,
  • read-only: for data objects that never change, no chance of inconsistency.
Lck