Hi All,
Just having a few issues with SysCache, I'm pretty sure its my ignorance on the issue but am having a bit of a hard time finding info on SysCache.
Anyways, for some reason it appears that the Cache is not working as I expect.  If I make changes to the database (outside of NH) I would expect these changes to be ignored, at least for the default expiration period.  Currently this is true during a single Session, but I assume this is a Session level cache. As soon as I close a session and start a new one the database gets re-read. From the documentation I have managed to find, the SysCache should only evict all objects when the SessionFactory is closed not the Session.
Thanks in advance,
Guido Tapia
A few details:
NH (And contrib) Version: 0.9
Mapping File:
Code:
<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="PicNet.RiskShield.DAL.Division, RiskShieldDAL" table="`Division`">
    <jcs-cache usage="read-write"/>
    <id name="ID" column="`DivisionID`" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="DivisionName" column="`DivisionName`" type="String" not-null="true" length="100"/>
  </class>
</hibernate-mapping>
Test Fixture:
Code:
[Test]
public void SimpleTest()
{
  // Gets a handle on a new session
  ISession s = DataFacade.GetSession();         
  Division d = new Division("_Name");
  s.Save(d);
  string nameQuery = "SELECT DivisionName from Division WHERE DivisionID = " + d.ID;
  Assert.AreEqual("_Name", (string) SqlHelper.ExecuteScalar(connection_string, CommandType.Text, nameQuery));
  // Change the name in the DB (bypassing NH)
  SqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, "UPDATE Division SET DivisionName = '_Name2' WHERE (DivisionID = " + d.ID + ")");
  Assert.AreEqual("_Name2", (string) SqlHelper.ExecuteScalar(connection_string, CommandType.Text, nameQuery));         
  // Reload the 'Division' object from the same session
  d = (Division) s.Find("FROM Division WHERE DivisionID = " + d.ID)[0];   
  Assert.AreEqual("_Name", d.Name);    // Pass
}
[Test]
public void SessionStartEndTest()
{
  ISession s = DataFacade.GetSession();         
  Division d = new Division("_Name");
  s.Save(d);
  Assert.GreaterThan(d.ID,  0);
  string nameQuery = "SELECT DivisionName from Division WHERE DivisionID = " + d.ID;
  Assert.AreEqual("_Name", (string) SqlHelper.ExecuteScalar(connection_string, CommandType.Text, nameQuery));
  // Change the name in the DB (bypassing NH)
  SqlHelper.ExecuteNonQuery(connection_string, CommandType.Text, "UPDATE Division SET DivisionName = '_Name2' WHERE (DivisionID = " + d.ID + ")");
  Assert.AreEqual("_Name2", (string) SqlHelper.ExecuteScalar(connection_string, CommandType.Text, nameQuery));         
  // Close the session
  DataFacade.EndASPSession();
  // Start a new Session (SessionFactory.OpenSession())
  DataFacade.StartASPSession();
  // Get a handle on the new session
  s = DataFacade.GetSession();
  d = (Division) s.Find("FROM Division WHERE DivisionID = " + d.ID)[0];
  // This fails, appears to have read value from the database
  Assert.AreEqual("_Name", d.Name); // Fail
}