Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way for NHibernate to inform query cache from views to be invalidated?

Tags:

nhibernate

I made a view out of joined tables, and I wanted its 2nd level query cache to be invalidated when the view's base table(s) are updated(within ORM context). The view is mapped like a table on NHibernate

Is this possible on NHibernate? How this is done on xml mapping? Fluent mapping will do too

like image 252
Hao Avatar asked Jun 18 '13 11:06

Hao


1 Answers

Believe or not, even this is possible with NHibernate. If you'd have for example class mapped like this:

<class name="Contact" table="[dbo].[Contact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>

And there is a view on top of the table [dbo].[Contact] which is mapped to another class:

<class name="ViewContact" table="[dbo].[ViewContact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>
    <!-- at this moment the View and table are treated differently -->

Then the magic setting goes directly under the <cache> and and is called <synchronize>

<class name="ViewContact" table="[dbo].[ViewContact]" lazy="true" >
    <cache usage="read-write" region="ShortTerm"/>
    <synchronize table="[dbo].[Contact]"/>
    <!-- now both caches are synchornized -->

And now, any changes to mapped class Contact will also trigger the cache cleaning of the ViewContact class mapped to the view

like image 190
Radim Köhler Avatar answered Oct 05 '22 23:10

Radim Köhler