Warning | ||
---|---|---|
| ||
Updating the course for FarCry 6.x. If you can help let us know! Put your notes in the comments for the page. |
Objectives
Excerpt |
---|
By the end of this unit you will be able to apply caching to various aspects of your applications to dramatically increase performance. |
Object Broker
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.
...
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 even keep track of embedded views, flushing all the relevant 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.
Note |
---|
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 Broker
The Object Broker is activated by adding component level metadata to your content type.
Code Block |
---|
<cfcomponent extends="farcry.core.packages.types.versions" displayname="Article"
hint="Standard article used in the site."
bObjectBroker="true"
objectBrokerMaxObjects="10000"
lObjectBrokerWebskins="display*">
|
bObjectBroker
Setting this to true
activates object-level caching for the specific content type. The default if you do not specify this attribute is false
.
objectBrokerMaxObjects
The maximum number of objects to be held in the Broker for this content type. The default if you do not specify this attribute is 100
. Typically you want to set this to a number that is high enough to hold all the records for this content type. The only reason not to is if you lack enough physical memory on the ColdFusion instance to accommodate them.
Object Broker Report
You 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 Types
Let's activate the Broker for the three content types we created earlier; superHero, superGroup and superPower.
- Open your Super Group type (./packages/types/superGroup.cfc) and update the component metadata
Code Block <cfcomponent name="superGroup" extends="farcry.core.packages.types.types" output="false" displayname="Super Group" bObjectBroker="true" objectBrokerMaxObjects="1000">
- Open your Super Hero type (./packages/types/superHero.cfc) and update the component metadata
Code Block <cfcomponent name="superHero" extends="farcry.core.packages.types.types" output="false" displayname="Super Hero" bObjectBroker="true" objectBrokerMaxObjects="1000">
- Open your Super Power type (./packages/types/superPower.cfc) and update the component metadata
Code Block <cfcomponent name="superPower" extends="farcry.core.packages.types.types" output="false" displayname="Super Power" bObjectBroker="true" objectBrokerMaxObjects="1000">
- Re-initialize the application to get your component changes registered in the application (ie. Update App!)
- Wander about the website clicking on a few pages; this will activate the Object Broker and start caching objects behind the scenes
- Open up the webtop Admin tab and review the Object Broker Report
View Caching
You can also cache the view layer very easily, either through metadata on the component or directly by specifying a caching directive in the webskin templates themselves's decorator.
lObjectBrokerWebskins
A list of webskins that should be cached. The default timeout for any webskin cache is 1400 minutes (or 24 hours). This seems like a long time, but remember they get automatically flushed if content within the view is updated.
You can list the webskin templates by name, for example:
Code Block |
---|
lObjectBrokerWebskins="displayTeaserFeature,displayPageStandard"
|
You can list the webskin templates using a wildcard, for example:
Code Block |
---|
lObjectBrokerWebskins="display*"
|
You can nominate a specific timeout in minutes for each template, for example:
Code Block |
---|
lObjectBrokerWebskins="displayTeaserFeature:30,displayPageStandard:60"
|
Note | ||
---|---|---|
| ||
Note | ||
| ||
Do not use |
Caching From the View
5.1 introduced the ability to nominate metadata within a specific webskin or view to control webskin caching.
...
A @@cacheStatus
is always required if you want to nominate a @@cacheTimeout
value.
Tip |
---|
Setting a |
Code Block | ||
---|---|---|
| ||
<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" /> |
Code Block | ||
---|---|---|
| ||
<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" /> |
Environment Changes
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.
...
@@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) warning@@cacheByRoles
is simply a boolean, so set it to0
or1
.
Note | ||
---|---|---|
|
...
The following inline template metadata options have been deprecated as of 5.1: |
...
Note | ||
---|---|---|
| ||
To correctly set the cache, you need to specify the full variable name. So, if you want to cache according to a url parameter (such as 'page') you need to set
|
Walkthrough: Add Caching to Super Hero
...
Tip |
---|
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. |
- Run some pages in the sample Mollio Fandango site and review the debugging output with your instructor using the Profiler; we're looking for views that might be beneficial to cache
- Open the ./packages/types/superHero.cfc for editing
- Modify the opening <cfcomponent> tag to include references to the Object Broker caching engine
Code Block <cfcomponent bObjectBroker="true" lObjectBrokerWebskins="display*">
- Add the
@@cacheStatus: 1
and@@cacheTimeout: 15
webskin decorators to the views you want to cache - Restart the application to activate the changes to the component metadata you have made
- Re-run the pages in your web site and review your findings with your instructor
Lab: Add Object Broker Caching To Super Group and Super Power
- Open up superGroup and superPower content types for editing
- Activate caching for all display templates
Walkthrough: Nested Webskin Cache Flushing
...
- relevant views
Bonus Lab: @@cachetypewatch
- Add a cache "type watch" to your listing pages to immediately capture changes to lists of a certain content type
Tip |
---|
For a list of all the available webskin decorators review: https://farcry.jira.com/wiki/display/FCDEV60/Summary+of+View+Decorators |