whatever

HOWTO: get scopes by name

I recently had a mail exchange with someone who wanted to get scopes by name, and was using undocumented methods on the PageContext to achieve his purpose. While this will work, there is an easier way…

You can do this using the StructGet function. StructGet attempts to gets a value from a named variable path which may traverse several nested structures, for example “my.dog.food”, where both “my” and “dog” are of type Struct; this may even be applied to scopes - “session.dog.food”. As the documentation notes, this function can be dangerous since it will create a path down to a variable if it doesn’t find it, but used carefully it can be incredibly useful.

In this case, the problem can be solved simply by passing the scope name to StructGet:

<cfset myscopename="server">
<cfset myscope=StructGet(myscopename)>

There you go, an abstract technique for getting scopes by name!

Update: The “someone” is none other than Jared, who has blogged about this too.

code
coldfusion
technology
whatever

Comments (2)

Permalink

Mumbai Blasts

India was again the victim of brutal terrorist attacks on Tuesday, 11th July. I would have, and probably should have, posted about this earlier, but somehow could not bring myself to do it. It really is easier to live in denial of violence rather than to accept the reality of its existence. Let me add my voice to the chorus already commiserating with the victims and their families and condemning the attack.

It is a tribute to the people of Mumbai that the aftermath of the blasts was not marred by communal violence, in a city that has already seen too much of it. The operative word in Islamic terrorist is terrorist. The same goes for any other group promoting violence as a means to their own ends. The communities that these terrorists may claim to be representing are largely peaceful folks just trying to get on with their lives.

Violence begets violence. Acting violently against terrorists or, more importantly, against their perceived consituencies only creates young men and women growing up in fear and anger, ripe for recruitment. Mumbai knows this, and so, her many disparate communities keep the peace amongst themselves that the city might be a safer place to live, that they can represent the plural society that India is. There is much we can learn from their example.

whatever

Comments (0)

Permalink

Tangled in the Template Cache

I started writing responses to all the great comments I got from my last post, but those rapidly grew so large and… ummm… tangled that it just seemed more manageable to just write a new post to address all of them!

Continue Reading »

coldfusion
technology
whatever

Comments (22)

Permalink

Tangling with the Template Cache

The ColdFusion template cache is an interesting beast; one which taught me a great deal about caching. I’ll be discussing the design of the template cache in this post, along with the rationale behind the approach that was taken, and some explanation of interesting behaviours that the template cache exhibits. Before we venture further, please do read An Introduction to Caching - you’ll need that information to understand the rest of this post.

What is the template cache?

For those who don’t know, the template cache is where ColdFusion stores compiled CFM and CFC templates in memory. When a template is executed for the first time, it is compiled to Java bytecode, and then stored in the template cache. Subsequent requests for the template use the compiled form of the template stored in the template cache, saving the overhead of having to read a file from disk, or even having to recompile a template. Templates are typically recompiled only when the CFM or CFC is modified, though if you’ve configured CF to not store compiled templates to disk, they will be recompiled any time they’re not found in the template cache.

Template cache configuration is managed from the ColdFusion Administrator under Server Settings > Caching. You can manage cache size and a couple of other settings, which I’ll get to later, on this page.

Continue Reading »

coldfusion
java
technology
whatever

Comments (17)

Permalink

Hear ye, hear ye!

Having finally got our own web space seems to have persuaded Anasuya to enter the blogosphere; it’s been a wonder watching her go from tentative first steps to absolute glee at seeing her work online. She’s a committed feminist who’s dedicated to combating injustice wherever it might be, and in my own (admittedly biased) view, a very original and balanced voice within the womens’ movement. Check her out!

anything else
whatever

Comments (3)

Permalink

Memory-sensitive Caching for CF

After my introduction to caching post, Doug Hughes asked whether it would be possible to wrap CFCs in soft references to create a memory-sensitive cache for use in CFML. I answered that it should, in theory, be possible, but that an implementation would have to take care of a few common design issues that occur when dealing with soft references.

Having said that, I sat down to write my own implementation to fill the dull hours between CFUNITED sessions…

Here’s softcache.cfc, a soft reference cache that you can drop into your applications. I have not tested this extensively; which is not to say that I haven’t tested it at all! If you do find any bugs, leave your comments here, and I’ll see what I can do about them. I’ve tried to comment the code as thoroughly as possible, but if there’s any particular point that is unclear, do leave a comment and I’ll try to explain it further.

Disclaimer: I spend most of my time writing Java code - if the CFML I write could be optimized further, do let me know.

Continue Reading »

code
coldfusion
technology
whatever

Comments (18)

Permalink

An Introduction to Caching

This is the first in a series of posts where I’ll discuss caching techniques, and how we apply them in ColdFusion.

So, what is a cache?

A cache in software terms means exactly the same as it does in any English dictionary, at least in the sense that it’s a store of items. More specifically, it’s often intended to mean a store of items that are kept in memory for fast access. Which brings us to our next question…

Why cache at all?

Consider that database table you have in your application, the one that is almost never changed, the one that you spend 99% of your time reading from, and only 1% of your time writing to. Do you really need to pay the cost of running the query against your database server each time? How about we just keep it in memory and so provide almost instantaneous access to the data.

Continue Reading »

coldfusion
java
technology
whatever

Comments (4)

Permalink

Stake Five

Welcome to Stake Five, my new home on the web, my virtual stake in the ground! I’ll be updating it as frequently as I can, with musings on technology, music, politics, and whatever else might catch my fancy.

In case you’re wondering where the name came from, my lovely wife is to blame - she suggested munging something to do with music, and this is what popped out…

While the Dave Brubeck Quartet’s Take Five may indeed be one of the most overplayed jazz tunes ever (a saxophonist friend of mine claims that a little bit of him dies every time he hears it!), there is an undeniable magic to the original, which I revisited after reading Tim Bray’s post on it a few weeks ago. If you’re reading this, Tim, thanks for the reminder! When I was getting into playing jazz, it was definitely one of those formative tunes that helped guide the way I thought about music - apart from the wonderful original, Aziza Mustafa Zadeh’s magnificent cover in particular got me thinking about how original forms can be stretched to accommodate the new.

And so I hope to do here as well - we stand on the shoulders of giants, after all!

anything else
music
whatever

Comments (2)

Permalink