Jun 6 2010

Caching In ColdFusion - Native Caching

Posted by Mike Brunt at 2:47 AM CloudComputing | Caching | ColdFusion | JRun-J2EE

Used effectively and managed well, caching is a very effective tool in building highly scalable web applications, for example Facebook and Twitter both use large distributed caching mechanisms to ensure acceptable performance with immense amounts of data. What is a cache in computing terms? Let's get it from "the horses mouth"; the EHCache users guide. "In computer science terms, a cache is a collection of temporary data which either duplicates data located elsewhere or is the result of a computation. Once in the cache, the data can be repeatedly accessed inexpensively".  EHCache is a Java based mechanism which ships natively with ColdFusion 9 and which we will get into in more detail on, later.  The purpose of this blog post is to list the different kinds of caching available to us in ColdFusion.  Here they are and we will indicate whether memory or disk based on each.  One very important point to bear in mind in this regard, if the caching is memory based the cache will reside within the same JVM memory spaces as everything else.  That space is very finite in 32-bit installs of ColdFusion.  Before getting into detail, I recommend you read a previous blog piece on something I called "Data Distance"  this gives an overview of data manipulation and caching is a major piece in manipulating data; effectively.

Another important need, in effective caching, is the ability to manage the cache, to see what is in there and to assess the success hit rate and to control cached content updates. We comment on this below in the "Management" sections.

Caching in ColdFusion has been around through many versions and in some cases only lasts for the duration of a single request unless coded to persist, an example of caching only for the duration of the request would be a request using "Query of Query", a very handy ColdFusion construct . In this section we will detail persistent caching in ColdFusion.  Typically caching is used in QA to gauge performance improvements via load-testing and in Production to deliver those performance gains to end users.  Caching should be off in development as of course we typically want to see the results of code changes immediately.

SHARED MEMORY SCOPES (MEMORY): This is often not seen as caching, per se, but it definitely is, if fact Ray Camden created a construct to utilize shared memory scopes for caching, it was called "ScopeCache". The shared memory scopes can contain simple or complex data types and are:

 

  • Server - Available to all applications and users on a single ColdFusion server.
  • Application - Available to all users in a single ColdFusion application as defined by the THIS.name = "foo"; 
  • Session - Available to a single user in a single application.

 

Management - Each scope can have a timeout set (THIS.sessionTimeout = createTimeSpan(0,0,20,0);) and the items in that scope will expire on reaching that time-out.  Alternatively, they can be overwritten by simply recreating them.  Items cached in shared memory scopes can be difficult to manage.  One last caveat here, if using shared memory scopes use the  tag when creating the cache to make sure that "race conditions" with unpredictable data do not occur.  The contents of single variables, nested variables or complete scopes can be viewed using the tag.

QUERY CACHING (MEMORY): Used effectively query caching can be a great performance enhancer, reducing multiple trips to the database by storing the resultsets in memory.

Management - Similarly to shared memory scopes, timeouts can be set using "CachedWithin" CachedWithin="#CreateTimeSpan(0,1,0,0) which will flush the cached content after that time.  Items stored within a cached query can be difficult to manage.  Note in ColdFusion Server Monitor, it is possible to get a snapshot of cached queries via the snapshot dumped via the Alter Configuration in ColdFusion administrator > Server Monitor, this can be useful in assessing the effectivity of cache hits.

CONTENT CACHING - CFCACHE (MEMORY): Cache copies of full page content on the server or client side. CFCACHE has simple URL parameter detection to assist in serving or not serving cached content.  There is also a timeout which can be set - timeout = "#DateAdd(datepart, number, date)#"

Management - Once again management of the cached content via CFCACHE is not easy and flushing what is there is achieved by overwriting existing content or when the timeout setting is reached.  There is a small amount of intelligence that can be passed via URL strings.

TEMPLATE-TRUSTED CACHE (MEMORY): Of all the pre ColdFusion 9 caching mechanisms my most preferred one is Trusted Cache.  Trusted Cache takes the parsed ColdFusion code in a template (not the view content) and caches it the first time it runs.  I have seen it deliver anything from 25% to 40% improvement in overall performance and it is predictable.

Management - Trusted Cache is enabled via the ColdFusion Administrator and there is a control to flush the cache there, so it is simple to control.  Any time new code is added or existing code changed the cache should be flushed.  Another important point in ensuring the effective use of Trusted Cache is to make sure the maximum number of cached templates is set to at least the total of all .cfc and .cfm templates in the ColdFusion application.  This is set in ColdFusion Administrator.

CACHE TEMPLATE IN REQUEST (MEMORY): ColdFusion 9: Caches a template for the duration of the Request. useful where multiple calls to same template in same request.  I often see multiple calls to the same template in applications which use cfc based frameworks.

Management - Effectively there is none as the items are only cached for the duration of the Request.

COMPONENT PATH CACHE (MEMORY): ColdFusion 9: This caches the path to CFC’s (when paths are deeply nested this can cause performance problems, so ideally deep nesting should be avoided, when coding applications).  

Management - As with Trusted Cache, this can be flushed via the ColdFusion Administrator.

SAVE CLASS FILES (DISK): When ColdFusion code is parsed it is compiled into Java classes which are in memory at that point.  Having this checked in the ColdFusion Administrator means that those classes will be saved to disk.  This is good both for ColdFusion performance between restarts and also for troubleshooting what code actually ran as the class file name is retained in the logs, should errors occur.

Management - Simply enabled via the ColdFusion Administrator.

CACHE WEB SERVER PATHS: In reality this should never be used unless there is a single web site on the web server in use which is highly unlikely.

Management - make sure this is turned off in the ColdFusion Administrator.

EHCACHE (Memory-Disk): ColdFusion 9: Native to CF9 a powerful Java based caching mechanism which can be local (heap) and is replicable-distributable. We are very excited about the possibilities afforded by EHCache as it brings the sorts of distributed caching mechanisms available to applications such as FaceBook and Twitter to ColdFusion.  We are just beginning evaluation and testing of EHCache and will publish our findings going forward.

Management - EHCache has programmable and sophisticated API's for assessing success rates and managing cache content; we will be blogging more on this in future articles on EHCache, specifically.

ORM HIBERNATE (Memory-Disk): - ColdFusion 9: Native to CF9, Object Relational Mapping for database abstraction, which uses EHCache as its caching mechanism.

Management - Managed at the code level.

VIRTUAL FILE SYSTEM (Memory): ColdFusion 9: In memory file storage which can be useful when handling files, temporarily.

Management - Managed at the code level.

In this blog piece, we have detailed all caching mechanisms available in ColdFusion 9 (as stated) and in previous versions of ColdFusion where not stated as ColdFusion 9.  Our next blog piece on caching will go into detail on using EHCache in Production applications.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Comments

CFWHISPERER

CFWHISPERER wrote on 08/12/10 12:03 AM

We are currently working with the creators of EHCACHE and Terracotta to bring something exciting to CF.
hr services

hr services wrote on 02/12/11 9:32 AM

The article was really wonderful and I enjoyed reading it. I have had a problem recently. I have deleted the cold fusion pages off the server and after a few months later, it appears there again. I just want to make sure that it doesn’t reappear again. I updated it and it was gone after a few days it was there again. Any idea what might be causing it? I am really looking forward to getting a feed back to solve the problem.
shiyan

shiyan wrote on 02/14/11 12:19 AM

.[url=http://www.pulati.cc/]???[/url] pilates.
torrent

torrent wrote on 02/24/11 8:00 AM

Nice post. I've been using the query cacheing for years but I've never really thought about it in this much detail. In the coldfusion monitor I'm not seeing any templates in cached queries list. The graph in the query cache status is working. Any suggestions?
nike air max 90

nike air max 90 wrote on 05/24/11 9:10 PM

Definitely agree with what you stated. Your explanation was certainly the easiest to understand. I tell you, I usually get irked when folks discuss issues that they plainly do not know about. You managed to hit the nail right on the head and explained out everything without complication. Maybe, people can take a signal. Will likely be back to get more. Thanks
acupuncture pain fl

acupuncture pain fl wrote on 06/02/11 12:29 AM

Knowing how acupuncture works, after that you can use it effectively as a nonstandard treatment for pain. An <a href="http://www.xinglinhealing.com/">acupuncture pain fl</a> will insert very thin needles into specific points in your body. Acupuncture was initially used in China nearly two millennia ago. It first started to get attention in Usa in 1971, because it was effective in relieving postoperative pain. In this article, we'll discuss the various theories regarding precisely how acupuncture works.

Chinese theories as to how acupuncture heals the human body differ greatly from those discussed in the West. Based on chinese medicine beliefs, there are two opposing forces anyway, yin and yang. These also occur in the body. Yin is very passive, while yang is very active.
Locksmith Paterson NJ

Locksmith Paterson NJ wrote on 06/24/11 12:31 AM

Top class help; I am going to absolutely keep returning to your blog post for more content.
<a href="http://www.PatersonNJLocksmithBest.Com">Locksmith Paterson NJ</a>
Custom flag

Custom flag wrote on 07/12/11 3:03 AM

ohh man this is awesome post.i think they should usebanner to get more flow in look.
you know this is great working by the writer.The writer has done a great job in speniding his time in
research about this article. can i subscribe all his posts ?
I am really happy to read this. i was searching this from last two months and atlast i got it. hurrah..!!
discount chanel handbag

discount chanel handbag wrote on 07/21/11 7:32 PM

A very good post . Thanks for sharing it. welcome to our website and we will give you a big discount for all the products.
cheap handbag

cheap handbag wrote on 08/22/11 7:54 PM

The concept of your article is pretty unique which is a good element in driving more individuals to read your site.I even told my friends to check out your blog and in fact your blog is already bookmarked on my computer. I am looking forward to see your upcoming post. Keep it up!
hermes

hermes wrote on 09/07/11 2:42 AM

Thanks a lot for sharing this. I have never thought that surfing online can be so much beneficial and entertained in a good shape. I feel really happy and grateful for providing me with such priceless sound track. All are good here simply best. I want such article again and again.
cuu du lieu

cuu du lieu wrote on 11/07/11 2:14 AM

The Government needs to come clean on what its Paid Parental Leave Scheme really means for working families, starting with its name.
superdry sale

superdry sale wrote on 11/18/11 6:07 PM

Every superdry sale fans convinced superdry will be next huge designer. The colors of superdry uk are just amazing because they are universally flattering! It is a great alternative for people who are tired of buying out the entire superdry outlet line and are finished shopping at Our Superdry uk sale store.
qjkider

qjkider wrote on 11/24/11 4:14 PM

Daily meticulously shaping a hair, will make people look extra spirit [url=http://www.bestlisseurghdfr.info/][b]ghd lisseur[/b][/url] Today we introduce some friends of female beauty does not hurt the hair shaping straight hair, [url=http://www.bestlisseurghdfr.info/][b]styler ghd [/b][/url]the product uses a high temperature ceramic plates, [url=http://www.bestlisseurghdfr.info/][b]lisser ghd[/b][/url] hair can minimize the damage will be. Straight hair looks elegant design [url=http://www.bestlisseurghdfr.info/][b]ghd hair straighteners[/b][/url] Body with a high temperature ceramic plates smooth and delicate texture to prevent their hair, [url=http://www.bestlisseurghdfr.info/][b]ghd france[/b][/url] to protect the scalp healthy.
handbags

handbags wrote on 02/07/12 9:09 PM

Thank you! You often write very interesting articles. You improved my mood.I'll be back again.
the best ipad case

the best ipad case wrote on 02/09/12 7:19 AM

I stumbled through the rest of your post and really give interest to every readers.
Insia Travel Packages

Insia Travel Packages wrote on 03/15/12 3:47 AM

I work in a graveyard shift. I was getting bored at work as no work here at office. So was searching through some blogs and came across your blog, great work man I liked what you wrote Inspirational and very meaningful.
Bauholz

Bauholz wrote on 03/31/12 1:16 AM

Amazing post full of gold. It definitely needs to be bookmarked.
Lifeguard Suits

Lifeguard Suits wrote on 03/31/12 3:29 AM

Thanks for sharing, it’s always great to find new and useful resources.
Jacob Panse

Jacob Panse wrote on 04/05/12 11:44 PM

It's really appreciating article.I used to search for these sort of article always.Thanks for sharing your creative writing abilities.
TN Pas Cher

TN Pas Cher wrote on 04/05/12 11:45 PM

rdry uk are just amazing because they are universally flattering! It is a great alternatbgfdg
rak toko swalayan murah

rak toko swalayan murah wrote on 06/17/12 10:10 AM

This posting is very cool and interesting post.This is a great inspiring article.I am very much pleased with your good work.You put really very helpful information in this site.

http://www.rakminimarket.com

therefore, I would like to thank you for the efforts you have made in writing this article.
Real Estate Oakville

Real Estate Oakville wrote on 06/25/13 12:29 AM

Our team of professionals provides our clients with a very convenient one-stop opportunity for their Mississauga real estate needs. Our team includes: a professional photographer, a professional writer, stager, assistants, competent lawyers, experienced mortgage lenders and brokers, invaluable home inspectors, trustworthy renovators and handyman and the list goes on. Call us today to discuss your real estate goals.
jeuxde918

jeuxde918 wrote on 11/17/13 11:36 PM

Great blog article about this topic,I have been lately in your blog once or twice now.I just wanted to say hi and show my thanks for the information provided….
sparxxrx

sparxxrx wrote on 10/16/14 8:52 AM

Conveniently coming in one size fits most, this lingerie is made of vinyl and nylon so it is sure to fit almost all body types. Simply slink into this sexy number and prepare for a wild night!
fashion tee

fashion tee wrote on 11/02/14 12:46 AM

Picking one out of many fashion jobs generally is an overwhelming challenge. There are several different opportunities in the fashion industry that you might not be sure which one is best for you.
bio technology job search

bio technology job search wrote on 11/02/14 12:46 AM

Networking is a critical part of your job search. It is time to update your networking arsenal and add the social media sites that can help you find a job.
communicat careers

communicat careers wrote on 11/02/14 12:46 AM

Even though it's important to exchange business cards, the purpose of networking isn't a competition to collect business cards, nor is it to conduct business.
healthy nc hospitals

healthy nc hospitals wrote on 11/19/14 6:51 AM

Genghis Bbq grill has partnered with Health care City Infirmary, a nationally accredited hospital operating out of Dallas, Colorado, to take Genghis Bbq grill fans quarterly cardiovascular healthy dishes options.
broad health

broad health wrote on 11/19/14 6:52 AM

Home medical helps older persons live on their own for while... -term nursing jobs home proper care. More exclusively, home medical may incorporate occupational along with physical treatments...
all consuming news

all consuming news wrote on 11/19/14 6:52 AM

The class leading published dailies took their content on the Cyber-space and they are providing your Indians readers a possibility to ingest news throughout Hindi- his or her mother language.
7d news

7d news wrote on 11/19/14 6:52 AM

To acquire exclusive, take a look at & smashing news involving Bangladesh State policies, ICT & Phone system Industry, Criminal offenses & Data corruption, Economic expansion, Energy, Aviation along with Op-ed stay linked with Online Reports Paper, Your Lead Reports and join free.
www.scorespro.com

www.scorespro.com wrote on 01/26/15 11:36 PM

It might seem that snow hockey will be too challenging to master as a grown-up but starting as a possible adult is very doable and also starting as a possible adult also has the advantages. Ice dance shoes is more difficult to understand than almost every other team sporting activities because you must learn the way to skate one which just learn the way to play snow hockey.
www.scorespro.com

www.scorespro.com wrote on 01/26/15 11:36 PM

The aim of a sports game is always to advance the particular ball and also score points in to the other clubs end zoom. The football may be advanced simply by throwing it to a new player which is known as a passing enjoy or having it which is known as a running enjoy.
Ibcbet

Ibcbet wrote on 01/27/15 3:53 AM

You should comment on the competition comparison of the blog. You can highlight it's mind boggling.
www.smartgridbusinessnetwork.org

www.smartgridbusinessnetwork.org wrote on 02/13/15 4:28 AM

Last time we introduced the new buzzword term, the Electric Smart Grid, provided a quick overview of the concept-undergoing-creation, and noted that doubts exist whether the utility industry can successfully implement it.
www.living-business.org

www.living-business.org wrote on 02/13/15 4:29 AM

If you are searching for an investment or perhaps a business having a guaranteed need, look absolutely no further! The actual outlook with regard to assisted residing is flourishing. Tens of an incredible number of baby boomers tend to be approaching retirement.
ristorante milano

ristorante milano wrote on 04/01/15 2:13 AM

Winter Restaurant Week 2008 launches in New York City this week, and provides a great opportunity to discover new restaurants or to experience pricier places you've been longing to try.
http://www.ristorante.milano.it
johnwilliams

johnwilliams wrote on 04/24/15 6:52 AM

nice post...
thron

thron wrote on 06/10/15 4:07 AM

Thanks for sharing us a great information that is actually helpful. Good day!
amazon

amazon wrote on 08/01/15 5:11 AM

thanks for the this valuable information
シャネル激安

シャネル激安 wrote on 10/24/15 3:38 AM

シャネルコピー、本物と同様です、シャネル激安非常に人気があります
財布、腕時計、靴、眼鏡、ピアス、バッグ一覧
日本一流品質のシャネルバッグ
シャネル財布
シャネル腕時計
シャネル靴
シャネル眼鏡
シャネルピアス新作最新入荷
人気シャネルコピー、N級ブランドシャネルのお求めはぜひ当店へ
シャネル全世界通信販売は6年前から行っております。
Financialprospect

Financialprospect wrote on 12/30/15 9:14 AM

finally i find a good site to get information and to read quality
articles thanks for sharing this type of articles its really hard
to find quality articles like this
son vo laptop

son vo laptop wrote on 01/16/16 11:40 PM

<a href="http://vicoso.blog.com/thay-vo-laptop/'>sơn vỏ laptop hcm</a>
ヴィトン激安

ヴィトン激安 wrote on 02/17/16 9:09 PM

品質もよい、ヴィトン激安でございます。
お客様に安心、ヴィトン激安信頼いただけるブランド品コピーをご提供するのを承諾します。
お注文した商品はお手元ヴィトン品と絶対同じ商品でございます。
バッグのヴィトンサイトがいつくがあります。
タマゴサミン

タマゴサミン wrote on 03/24/16 10:19 PM

Hello my friend! I want to say that this article is awesome, nice written and include almost all significant infos. I would like to see more posts like this.
車値引き

車値引き wrote on 03/28/16 12:20 AM

車の購入を検討している方にオトク情報
沖縄もずく

沖縄もずく wrote on 03/29/16 11:03 PM

Well I sincerely enjoyed reading it. This tip provided by you is very helpful for good planning.
ホームページ制作

ホームページ制作 wrote on 03/30/16 6:55 AM

Very efficiently written information. It will be supportive to everyone who usess it, including myself. Keep doing what you are doing – for sure i will check out more posts.
車下取り

車下取り wrote on 04/02/16 10:56 AM

車を個人で売りたい方にお得な情報をご紹介します。
typyhqxi

typyhqxi wrote on 04/14/16 9:29 AM

-1' OR 3+646-646-1=0+0+0+1 --
csr racing hile apk

csr racing hile apk wrote on 05/27/16 3:52 PM

I found your this post while searching for some related information on blog search...Its a good post..keep posting and update the information.
برامج

برامج wrote on 07/19/16 11:23 PM

nice post
برنامج الاذان

برنامج الاذان wrote on 07/19/16 11:28 PM

I am happy to find this post very useful for me, as it contains lot of information. cdsvsdvsdvs Thanks for your sharing good info.
مواقيت الصلاة القاهرة

مواقيت الصلاة القاهرة wrote on 07/19/16 11:33 PM

hdjgfkhgj,mbnvcbcc jtktgkmhngdfhgbv
مواقيت الصلاه

مواقيت الصلاه wrote on 07/19/16 11:34 PM

going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives in depth information.
مواعيد الصلاة

مواعيد الصلاة wrote on 07/19/16 11:41 PM

vzbxgcvhfkufxvg cvfd trdxtfyhg
ماسنجر

ماسنجر wrote on 07/19/16 11:43 PM

load testing of Zeus as yet but will be doing so
bolatangkas

bolatangkas wrote on 08/29/16 1:34 AM

This is really amazing. Such detail!
Partition

Partition wrote on 11/11/16 5:25 AM

Create this charitable of companions you consideration about precisely what therefore grief-favored beside contemplates to most of these tows which are fact produced.
foreclose real estate

foreclose real estate wrote on 11/14/16 5:18 AM

A great thesis adapt wish to provide naive veggies accompanying their patrons in appendage to. It actually is size of the authentic emphasiss that they can can shown their educating internal the section. For various musts, I well-being pro prescribed an separate downright propitious so fulfill. Got it pivot feather more been by your plans about the bough, I did flanked consequently Worn to do merely no laziness how to wend.
wedding photography NJ

wedding photography NJ wrote on 11/22/16 1:44 AM

Thank you for your share. I found your website perfect for my needs. It contains wonderful and helpful information. I have read most of them and got a lot from them.