Thursday, September 22, 2011

Caching in ColdFusion-Brief Overview

Well... Am sure most of us will be aware of what a Cache does.It is nothing but a component that temporarily stores data so that it can be referenced when future requests to the same data are made at a faster rate. Thus, it saves the time required to access the data from the disk or any other location improving the efficiency. The various advantages of caching are:

1. Enables accessing of the data at a faster rate.
2. Improves performance
3. In case of Web based applications, caching reduces the load on the Web server or Application server.
4. Increases reliability.(If the main server goes down, then data can be retrieved from the cache or vice-versa)

Adobe ColdFusion is an application server which enables developers to build, deploy and maintain large Internet based applications which store large amount of data. Since large amount of data transactions will be carried out, caching is a very important requirement. In case of ColdFusion a Web cache sits in between one ore more Web servers and one or more clients. This Web cache stores the data and can be accessed when the request for that data is made. This avoids the call to the Web Server to fetch the data thus reducing Latency. As the data is reused it reduces the representations used by the client which reduces the amount of bandwidth used by the client.  This lowers Network Traffic. Since the load is borne both by the Web cache and the Web Server's Database or the App server's database, the memory is efficiently managed which reduces the Garbage collection and the load is efficiently distributed. This makes the data more reliable since data is present in both the places and if server goes down data can still be retrieved from the cache.

proxy_caching.jpg

We all know that ColdFusion makes use of ehcahe as the cache provider for caching data. By default, the ehcache is stored within the CF address space. The different Caching architectures which are used are:

  1. In-Process Architecture : Operates in the same JVM as the application server. It has limited scalability for 32-bit systems as memory constraint must be considered. The data access is faster in this architecture as data/object serialization is not required.                                                                                             
  2. Out-of-Process Architecture : Operates in its own process outside the application server's JVM. It is highly scalable on both 32-bit and 64-bit platforms. It is generally slower than In-Process architecture as data/objects must be serialized/deserialized. 

The different types of Cache regions present in ColdFusion by default are:
  1.     Object Cache: It is the most flexible way to cache data. it can cache anything put in a ColdFusion variable.It has granular control over cache functions.It has access to the various cache item meta data such as cache_hitcount,cache_misscount,hitcount,idletime etc. It uses ehcache as cache provider.
  2.     Template Cache :  It can be used to cache a whole page by placing a <cfcache> tag at the top for the page. It can cache page fragments by placing the <cfcache> tag in between pages which have to be cached. It is useful when part of the page should be dynamic. It uses ehcache as cache provider
ColdFusion had caching in the <cfquery> tags in the previous versions. Query cache does not use ehcache as cache provider. In version 9, there were many enhancements added. Some of them were:
  1. Disk based and Memory based Caching
  2. Cfcache to use ehcache as default cache provider. This ehcache.xml is present under     <coldfusion_home>/lib directory
  3. Caching Page Fragements
  4. Introduced new functions such as
      *cacheGet
      *cachePut
      *cacheGetAllIds
      *cacheGetMetaData
      *cacheGetProperties
      *cacheSetProperties
    Refer to http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1b05d- 7fe1.html for detailed explanation.
 5. New attributes are added to the <cfcache> tag . Refer
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d5a.html for detailed explanation.




13 comments:

  1. Damn, and today , sitting right across, i was struggling with cfcache!
    nice entry.. gr8 start!

    ReplyDelete
  2. Kavya, welcome to the CF blogging community. Word is spreading about your entry into the space, so nice start. :-)

    About your entry above, though, I want to add some information that seems missing, and offer some clarifications that seem needed, to avoid folks making mistaken conclusions. I'm torn as to whether I should offer them here (as a long comment) or as a link to an entry on my own site. Someone could argue against whichever I chose, so I'll just go ahead and share the thoughts here. I just want to help readers (and perhaps you) as they contemplate what you've so kindly shared.

    First, you say that "In case of ColdFusion a Web cache sits in between one or more Web servers and one or more client", and your diagram shows that too, but I'm curious: there's no aspect of CF that enables that (a cache between the clients and the web server). Further, as for the diagram, wouldn't most traditional "web caches" be between the internet and the web server, instead?

    Second, as for the new ehcache-based caching, that's not "outside" of CF at all. I realize you may know that, but the diagram and phrase quoted above could lead a reader to think it is. By default, that new ehcache caching is stored *within* the CF address space. And even if it is configured to use external ehcache servers, those would be shown "below" CF in diagram above, I'd think.

    Not picking on you. Just want to be sure people make the right conclusions.

    Third, you say, "The different types of Cache present in ColdFusion are...object...and template cache". But you acknowledged earlier in the entry that CF has long had caching on CFQUERY, so it would be more accurate to add "query caching" to the list of "the types of cache present in CF". (You don't say elsewhere that you're limiting your discussion to ehcache-based caching, added in CF9. And if anyone may wonder, query caching is NOT based on ehcache.)

    Finally, it may also help to mention, to be complete (and for those to whom all this may be relatively new information), that there is still another form of caching in CF, sadly with the same name as one of those new cache features. Some will know that CF has long had a "template cache", which has no connection at all to the ehcache-based "template cache" mentioned above.

    This older form of "template cache" holds caching of the compilation of CFML templates, and is always on, to enable reuse of that saved compilation. You can only control the size of it, in the CF Admin. The newer form of "template cache" (yes, same name) is, as Kavya notes above, used instead for programmatically storing page *content* for reuse. So technically that is two kinds of additional caching, at least, that could be added to your list above.

    It's really quite unfortunate that part of the CF team chose to name this new caching "template caching", when there was already the older feature with the same name and quite a different purpose. I've heard many people get confused by this.

    Hope all that helps some readers.

    Certainly no offense intended to you, Kavya, in offering the additional info. Please don't let this sort of feedback dissuade you. You'll find that the community is very much about mutual support. (Sadly, some people may regard a comment like mine to be condescending, no matter how I word it to avoid it. I wish they'd see I'm just trying to help everyone who may read this.)

    Anyway, Kavya, I'm sure we'll all welcome future forays into the world of CF by you (and indeed any members of the Adobe CF team)! :-) I'm sure there will be many things you guys can share that would surprise and delight even old-timers like myself.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. @Charlie : sorry your comment had not been published. It was sent to the spam folder. I just happened to see it now. Firstly, thanks a lot for the valuable feedback provided. I have incorporated some of the changes suggested. Secondly, in my post where I mentioned about the different caches I was intending to highlight the default cache regions. I have made changes to highlight tat query caching does not use ehcache as cache provider.

    ReplyDelete
  5. Thanks for the clarification, Kavya. I'd still think there to be room for confusion, with the rewrite, but we can let the comment stand to assist readers, if it may be helpful.

    As for the comment going to spam, that's odd as there were no hyperlinks or anything. Was this in fact a spam tracker in your blog comment approval system, or rather in your mail client, based on an email sent to you when we comment? Just curious.

    ReplyDelete
  6. According to Stanford Medical, It is indeed the one and ONLY reason women in this country get to live 10 years more and weigh on average 42 lbs less than we do.

    (And really, it is not related to genetics or some hard exercise and really, EVERYTHING related to "HOW" they eat.)

    P.S, I said "HOW", and not "what"...

    Tap on this link to discover if this brief quiz can help you unlock your true weight loss potential

    ReplyDelete
  7. Florida is a beautiful state with lots of sandy beaches and beautiful warm weather. No wonder it's the number one choice for people who are considering where to go to drug rehab , addiction treatment or alcohol rehab.
    inspirational quotes for addiction
    rehab quotes

    ReplyDelete
  8. Mastodon was at first made to give a substitute to Twitter. Be that as it may, it's comprehensive grown-up content strategies that permit NSFW content on board has

    driven it to be one of the amazing NSFW YesPornPlease bloggers shelters. There is even an index on the site for YesPornPlease 'home to all past YesPornPlease clients'.

    All things considered, the site is centered around giving a sheltered spot to those in the NSFW and LGBT people group. In the event that you asked me it seems like a quite inviting and a completely go-to site for any ex NSFW Tumbler.
    yespornplease

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete