
593
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
Cache the association data of a persistent object
In this case, the primary key of the associated objects are cached. It does not cache the objects loaded as part of the
association unless caching is enabled for those objects. To cache an association, specify the following attributes on the
association property.
•
cacheuse
: Defines the caching strategy.
•
cachename
: Defines the name of the cache region to be used by the secondary cache provider. If you do not specify
a region name for the association property, the <comoponent_name>.<property_name> is considered as the cache
name. In case a region is not specified in the configuration file, a region is automatically created with the default
configuration.
For example:
<cfproperty name="art" fieldtype="one-to-many" cfc="CArt" fkcolumn="ArtID"
cachename="ArtistArts" cacheuse="read-only">
Cache query data
In this case, the results of queries that are executed by
ORMExecuteQuery()
or
EntityLoad()
methods are cached in
the secondary cache. To enable caching query data, pass "
cacheable=true
" and
"cachename='cachename'
values in
the options struct of the methods. If you do not specify the
cachename
, the query is cached in the default query cache.
It is recommended that you to specify the
cachename
so that you can control eviction.
For example:
availableArts = ORMExecuteQuery("from CArt where issold=0", {}, false, {cacheable=true,
cachename="availableArtsQuery"});
Secondary cache example using EHCache
Step 1: Set the following in
Application.cfc
:
<cfset this.name="Caching_Example">
<cfset this.datasource="cfartgallery">
<cfset this.ormenabled="true">
<cfset this.ormsettings.secondarycacheEnabled=true>
<cfset this.ormsettings.cacheProvider= "ehcache">
<cfset this.ormsettings.cacheConfig="ehcache.xml">
Step 2: Define the cache settings in the CFCs.
CArtist.cfc
<cfcomponent persistent="true" schema="APP" table="Artists" cachename="artist"
cacheuse="read-only">
<cfproperty name="artistid" fieldtype="id"/>
<cfproperty name="firstname"/>
<cfproperty name="lastname"/>
<cfproperty name="state"/>
<cfproperty name="art" fieldtype="one-to-many" cfc="CArt" fkcolumn="ArtID"
cachename="ArtistArts" cacheuse="read-only">
</cfcomponent>
CArt.cfc
<cfcomponent persistent="true" schema="APP" table="Art">
<cfproperty name="artid" generator="identity" fieldtype="id"/>
<cfproperty name="artname"/>
<cfproperty name="issold"/>
</cfcomponent>
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...