NHibernate Cache (SLC) not updating collection cache when child entity deleted/created

30 Views Asked by At

I just started using NHibernate Cache (Second Level Cache) with Redis provider.

I have Student entity which has a bag of MailingAddress entity. And when I load a contact then I see a redis key Student.Addresses#id which contains an array of connected mailing addresses ids.

If I call MailingAddress API to create new mailing address or delete an existing one for a student then that key Student.Addresses#id is not updated.

Everything is done inside transactions.

  <class name="MailingAddress" table="MailingAddress">
    <cache include="all" usage="read-write" />
    <id name="ID" type="System.Int64" column="ID">
      <generator class="identity" />
    </id>
    <property name="Address1" column="Address1" />
    <property name="StreetName" column="StreetName" />
    <many-to-one name="Student" cascade="none" lazy="proxy" fetch="select" class="Entity.Student" column="StudentID" />
  </class>
  <class name="Student" table="Student" discriminator-value="0">
    <cache include="all" usage="read-write" />
    <id name="ID" type="System.Int64" column="ID">
      <generator class="identity" />
    </id>
    <discriminator column="ContactType" type="int" insert="false"/>
    <property name="LastName" />
    <property name="FirstMidName" />
    <bag name="Addresses" inverse="true" cascade="all-delete-orphan" fetch="select" lazy="true">
      <cache include="all" usage="read-write" />
      <key column="StudentID" />
      <one-to-many class="Entity.MailingAddress" />
    </bag>    
  </class>
0

There are 0 best solutions below