By the end of this unit you will be able to apply caching to various aspects of your applications to dramatically increase performance. |
The Object Broker is a super piece of caching technology for the integrated ORM of FarCry Core. In simple terms it speeds up the access to data in the database by only retrieving the data once, then using in-memory storage to provide fast access for subsequent requests. You really want to turn this on. The goodness provided is only limited by the the memory available to your ColdFusion instance.
The Object Broker manages the population and refreshing of its cache. You don't really need to do anything more than activate the service for the specific content types you desire.
In addition to specific database calls, the Object Broker can also manage caching of all views. Remember a view or webskin is like a fragment of output, such as HTML. Generally a page request is made up of one or more views. The Object Broker's webskin cache will keep track of embedded views, flushing all the related views whenever a relevant content item is changed. This ensures that your changes are directly reflected in the view without having to be involved in any complex cache management.
The objectbroker cache is stored per application. In clustered solutions its possible for application instances to get out of synch. Daemon has a commercial plugin for the FarCry Platform to help provide high availability in clustered solutions: FarCry HA Plugin. Activating Object BrokerThe Object Broker is activated by adding component level metadata to your content type.
bObjectBrokerSetting this to objectBrokerMaxObjectsThe maximum number of objects to be held in the Broker for this content type. The default if you do not specify this attribute is Object Broker ReportYou can check which content types have been activated for the Object Broker by running the Object Broker Report under the webtop Admin tab, Cache Management menu. This should indicate those content types using the Object Broker, their maximum threshold and the current number of objects in the Broker. Walkthrough: Activating the Object Broker for Content TypesLet's activate the Broker for the three content types we created earlier; superHero, superGroup and superPower.
View CachingYou can also cache the view layer very easily, by specifying a caching directive in the webskin's decorator. Do not use |
5.1 introduced the ability to nominate metadata within a specific webskin or view to control webskin caching.
@@cacheStatus
: 1 caching, 0 default, -1 nothing can cache@@cacheTimeout
: (in minutes)A @@cacheStatus
is always required if you want to nominate a @@cacheTimeout
value.
Setting a |
<cfsetting enablecfoutputonly="true" /> <!--- @@displayname: Mugshot Teaser for Super Hero ---> <!--- @@cacheStatus: 1 ---> <!--- @@cacheTimeout: 15 ---> <!--- tag libraries ---> <cfimport taglib="/farcry/core/tags/webskin/" prefix="skin"> <skin:buildLink objectID="#stobj.objectid#"> <cfoutput><img src="#application.url.webroot##stobj.imgHero#" class="thumbnailLeft" /></cfoutput> </skin:buildLink> <cfsetting enablecfoutputonly="false" /> |
<cfsetting enablecfoutputonly="true" /> <!--- @@displayname: Mugshot Teaser for Super Hero ---> <!--- @@cacheStatus: -1 ---> <!--- tag libraries ---> <cfimport taglib="/farcry/core/tags/webskin/" prefix="skin"> <skin:buildLink objectID="#stobj.objectid#"> <cfoutput><img src="#application.url.webroot##stobj.imgHero#" class="thumbnailLeft" /></cfoutput> </skin:buildLink> <cfsetting enablecfoutputonly="false" /> |
In some cases you need the view to respond to changes on the URL, form post, client session, security role or other environmental factor. For example, in the case of a paginated result set you may be changing the displayed list of teasers based on a URL parameter such as "&pg=2". This is often awkward for caching regimes as you really need to use a hash of the query string in order to be sure you are looking at the right cache.
There are two specific options for managing environmental cues for caching:
@@cacheByVars
: used for any arbitrary variable you may wish to key the cache by. To correctly set the cache, you need to specify the full variable name. For example, if you want to cache according to a url parameter (such as 'page') you need to set @@cacheByVars: url.page
@@cacheByRoles
: used to key webskin caches by security roles (to allow for different views dependent on different privileged access levels to be cached in the presentation tier) @@cacheByRoles
is simply a boolean, so set it to 0
or 1
.
The following inline template metadata options have been deprecated as of 5.1: |
Don't forget to give both webskin tracer and farcry profiler a workout. These developer tools are especially helpful when working with caching. See Unit 4 for more information. |
<cfcomponent bObjectBroker="true"> |
@@cacheStatus: 1
and @@cacheTimeout: 15
webskin decorators to the views you want to cacheFor a list of all the available webskin decorators review: https://farcry.jira.com/wiki/display/FCDEV60/Summary+of+View+Decorators |