سطح دوم کش در Nhibernate 4
نویسنده: احسان زینلی
تاریخ: ۱۳۹۳/۰۷/۰۸ ۹:۴۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache" requirePermission="false"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string_name">LocalSqlServer</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.keywords">none</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
</session-factory>
</hibernate-configuration>
<syscache>
<cache region="LongExpire" expiration="3600" priority="5"/>
<cache region="ShortExpire" expiration="600" priority="3"/>
</syscache>
</configuration> <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Core.Domain" namespace="Core.Domain.Model">
<class name="Organization" table="Core_Enterprise_Organization">
<cache usage="nonstrict-read-write" region="ShortExpire"/>
<id name="Id" >
<generator/>
</id>
<version name="Version"/>
<property name="Title" not-null="true" unique="true"/>
<property name="Code" not-null="true" unique="true"/>
</class>
</hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Core.Domain" namespace="Core.Domain.Model">
<class name="Party" table="Core_Enterprise_Party">
<id name="Id" >
<generator />
</id>
<version name="Version"/>
<property name="Username" unique="true"/>
<property name="DisplayName" not-null="true"/>
<bag name="PartyGroups" inverse="true" table="Core_Enterprise_PartyGroup" cascade="all-delete-orphan">
<cache usage="nonstrict-read-write" region="ShortExpire"/>
<key column="Party_id_fk"/>
<one-to-many/>
</bag>
</class>
</hibernate-mapping> public IList<Organization> Search(QueryOrganizationDto dto)
{
var q = SessionInstance.Query<Organization>();
if (!String.IsNullOrEmpty(dto.Title))
q = q.Where(x => x.Title.Contains(dto.Title));
if (!String.IsNullOrEmpty(dto.Code))
q = q.Where(x => x.Code.Contains(dto.Code));
q = q.OrderBy(x => x.Title);
q = q.CacheRegion("ShortExpire").Cacheable();
return q.ToList();
}