Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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, 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. Objectbrokers webskin cache will even keep track of embedded views, flushing all the relevant 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.

Activating ObjectBroker

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

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 objectbroker, 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.

  1. Open your SuperGroup 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">
    
  2. Open your SuperHero 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">
    
  3. Open your SuperPower 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">
    
  4. Re-initialize the application to get your component changes registered in the application (ie. Update App!)
  5. Wander about the website clicking on a few pages. This will activate the object broker and start caching objects behind the scenes.
  6. 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 in the webskin templates themselves.

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.

...

Note
titleUsing Wildcards

Although using wildcards are great for caching whole sets of webskins, be careful. Best to be specific about your caching strategy; simplistic caching models can very quickly get you into trouble (wink)

Caching From the View

5.1 introduced the ability to nominate metadata within a specific webskin or view to control webskin caching.

...

Code Block
titleExample of Enforcing No Caching
<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.

...

Note
titleUsing cacheByVars

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

Code Block
@@cacheByVars: url.page

Walkthrough: Add Caching to Super Hero

  1. Open the ColdFusion Administrator and turn on debugging times for the server.
  2. Run some pages in the sample Mollio site and review the debugging output with your instructor.
  3. Open the ./packages/types/superhero.cfc for editing.
  4. Modify the opening <cfcomponent> tag to include references to the object broker caching engine
    Code Block
    <cfcomponent bObjectBroker="true" lObjectBrokerWebskins="display*">
    
  5. Restart the application to activate the changes to the component metadata you have made.
  6. Re-run the pages in your web site and review your findings with your instructor.

Lab: Add Object Broker Caching To SuperGroup and SuperPower

  1. Open up supergroup and superpower content types for editing
  2. Activate caching for all display templates

Walkthrough: Nested Webskin Cache Flushing

1. View a superHero page and notice the caching
2. Edit a superGroup and change the title.
3. Refresh the superHero page and notice that the superHero was flushed because a nested webskin needed flushing.