Persistence with ColdFusion Builder Extensions

Here’s a question - how would you handle persistence in a ColdFusion Builder extension? Most extensions are “fire and forget” - they may have a few steps but in general the idea is - take some input, do some action, return some output. There are - however - times when you may want to remember stuff. For example, perhaps your extension has numerous options and you simply want to remember what the user picked last time. A while ago I released a component called builderHelper. This component wrapped up common tasks for extension developers and aimed to make working with the XML dialect of CFB extensions even simpler. Today I whipped up a super simple method of persistence. Any extension making use of builderHelper can store settings use name/value pairs. The name must be unique per extension and the value can be anything that is serializable by JSON:

<cfset helper = createObject("component", "testingzone.builderHelper.builderHelper").init(ideeventinfo)> <cfset prefs = helper.getStorageItem("prefs")> <cfdump var="#prefs#"> <cfset helper.setStorageItem("prefs", {x=1})>

In this code sample I initialize builderHelper with my ideeventinfo packet. I then ask for and dump a value called prefs. The first time I run this it will be blank. Then I set a value, in this case a struct with one key. The second time I run this particular extension it will get the structure back. A pretty trivial example but hopefully you get the idea.

You can download this code at the RIAForge project:

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA