Cache (Reference) Part 3

February 12, 2010 · By Michael Offner · 2 Comments

Before we begin the last part of the cache blog, let's do a little review.

In the first part, I have shown how the cache is used as an object cache, how to create a cache and interact with it but not more. The second part was on everything that is possible with the cache, and for what it can be used. In the last part we want to see at some special cases and deliver the promised reference.

Of course you know that the entire cache implementation was not our idea, but this is part of the CFML2009 specification and implemented accordingly in Adobe ColdFusion. For this reason, we could not make the implemnetation completely free of restrictions but had to follow a certain interface (tag and function interface). However, we have extended our implementation with some features that seemed important and which resulted in the alpha testing.

The biggest difference lies in the fact (described in part 2) that you can create as many caches as you want. In addition you have several different cache implementations available as extensions. Railo itself uses the cache as a backend for cached queries, templates and ram resources.

Next to these Railo offers a variety of optimizations for the existing "Object Cache" implementation. I guess it's best if we mix the special cases with the reference, and start with this it Features that are not specified in CFML2009 and do not exist in Adobe ColdFusion, are marked in red.

cacheClear([string filter[,string cacheName]])
Flushes the cache. You can specify a key filter for the elements in the cache to flush, the filter follow the same rules as for cfdirectory-filter. With the second Argument you define the cache instance used by name (by default the "default Object Cache" is used).

cacheCount([string cacheName])
Returns a count (integer) of keys stored in the cache. With the first Argument you define the cache instance used by name (by default the "default Object Cache" is used).

cacheDelete(string id,[boolean throwOnError[,string cacheName]])
Deletes a single element from the cache, the id of the element can also contain a ",". With the second argument you can define if the functions throws a exception when the element does not exist (default is false). With the third Argument you define the cache instance used by name (by default the "default Object" Cache is used).


cacheGet(string id[,boolean throwWhenNotExist[,string cacheName]])
Returns a element from Cache that match the given key. With the second argument you can define if the functions throws a exception when the element does not exist (default is false) With the third Argument you define the cache instance used by name (by default the "default Object" Cache is used).

cacheGetAll([string filter[,string cacheName]])
this function return a structure containing all elements inside the cache. You can specify a key filter for the elements with the first argument, the filter follow the same rules as for cfdirectory-filter. With the second Argument you define the cache instance used by name (by default the "default Object" Cache is used).


cacheGetAllIds([string filter[,string cacheName]])
this function return a array containing all keys inside the cache. You can specify a key filter for the elements with the first argument, the filter follow the same rules as for cfdirectory-filter. With the second Argument you define the cache instance used by name (by default the "default Object" Cache is used).

cacheGetMetadata(string id[,string cacheName])
returns a structure with some Metadata regarding the cache elements (keys returned depends on the Cache type used). With the second Argument you define the cache instance used by name (by default the "default Object" Cache is used).

cacheGetProperties([string type])
returns array with different properties about the cache (keys returned depends on the Cache type used). first argument "type" define to whitch cache instances information are returned
  • "" or not set - information to all default caches (object,template,resource,query)
  • "object" - information to "Default Object" Cache
  • "template" - information to "Default Template" Cache
  • "query" - information to "Default Query" Cache
  • "resource" - information to "Default Resource" Cache
  • <cache name> - information to a specific cache


cacheKeyExists(string key,[string cacheName])
Returns true/false whether the cache contains an element with the certain keyname. With the second Argument you define the cache instance used by name (by default the "default Object" Cache is used).


cachePut(string id,object value,[timespan timeSpan[,timespan idleTime[,string cacheName]]])
puts an element with a id into the cache, with a life time and an idle time. With the 5th Argument you define the cache instance used by name (by default the "default Object" Cache is used).

cacheRemove(object ids,[boolean throwOnError[,string cacheName]])
removes elements from cache defined with argument ids, this can be a string list of multiple elements or a array containing keys. With the second argument you can define if the functions throws a exception when the element does not exist (default is false). With the third Argument you define the cache instance used by name (by default the "default Object" Cache is used).

cacheSetProperties(struct type)
sets some properties for a certain cache (settings depends on cache type used). This function is not supported by Railo, because we see this as a security risk, you can modifie cache configuration wihout a password, you can use tag cfadmin instead. we will add support for this function in a future release, but then you can enable,disable this function in admin for every single cache instance. <cfcache
[action = "string"]
[cache directory = "string"]
[cachename = "string"]
[directory = "string"]
[expireurl = "string"]
[id = "any"]
[idletime = "timespan"]
[key = "string"]
[metadata = "string"]
[name = "string"]
[password = "string"]
[port = "number"]
[protocol = "string"]
[throwOnError = "boolean"]
[timeout = "any"]
[timespan = "timespan"]
[username = "string"]
[value = "any"]>

</ cfcache>
This tag has two functions: you can manipulate data in the "Object Cache" (just like the functions cacheGet, cachePut, cacheClear) by using the actions "get, put, clear". In addition, you can still use it to cache pages as well. With the attribute "cachename" you define the cache instance to be used by its name (by default the "default Object" cache is used).

Now we see that Railo not only uses the cache for different purposes, but also thet the possibilities of the object cache have been greatly expanded. For us, however, the are many more ways in how the cache can be used. Whe have already thought of other use cases for the cache. One idea is to use the cache as a backend for the client scope where instead of a database you could use a cache for it as well.

If you have a good idea where it would make sense to use the cache as well please let us know.

Tags: cache · CFML · Community · Configuration · Railo 3.1.2 · Reference

2 responses so far ↓

  • 1 Nathan Miller // Apr 15, 2010 at 2:58 AM

    When I try to use cachegetmetadata I get a java.lang.noclassdeffounderror. I've tried the following syntax:

    &lt;cfdump var=&quot;#cachegetmetadata('test')#&quot;&gt;
    &lt;cfset meta = cachegetmetadata('test')&gt;

    What am I missing? I'm running 3.1.2 on CentOS (2.6.18-92.1.22.el5xen)
  • 2 Gert Franz // Apr 15, 2010 at 10:06 AM

    Nathan,

    do you have a complete stacktrace for me? Just send it to my usual eMail address: gert (at) getrailo (dot) com

    Gert

Leave a Comment

Leave this field empty: