Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Fun with mappings and resources: Part 2 RAM Resources

April 3, 2009 ·

In my last post I wrote about using ZIP and FTP as resource locations.

Today, I want to focus on why you might want to use RAM as a resource. Imagine the situation, for some crazy reason, you happen to have some code in your database, that you want to actually run. Its in fact just a text string, but you want to run this code. Let's say it is a code example in a blog post or something. How would you get this code to run?

A good way to do this is to setup a ram resource, this is fairly easy, again in a mapping you can create:

Virtual: ramdisk
Resource: ram:///

Now all we have to do in our code is:


<cffile action="write" file="/ramdisk/test.cfm" output="<cfdump eval=server>">
<cfinclude template="/ramdisk/test.cfm">
       
And what you should see is that the string "<cfdump eval=server>" has been executed and rendered correctly!
    
Very useful if you want to cache and execute content, or just for temporary files!

Tags: coldfusion · railo

10 responses

  • 1 Todd Rafferty // Apr 3, 2009 at 4:40 PM

    To be clear, in my Application.cfc I would use:
    <cfset this.mappings['/ramdisk'] = "ram:///">?

    or would this be safer to setup in the Server admin?
  • 2 Mark Drew // Apr 3, 2009 at 6:44 PM

    This would work as well, depends if you want it available for all the applications in that context/server (depending which admin you used) or if you want that to be specific to your application.
  • 3 Luis Majano // Apr 4, 2009 at 5:42 AM

    You can also use this approach to do code generation. You can generate functions or cfc in ram, and then mix them in very easily.
  • 4 Martijn van der Woud // Apr 5, 2009 at 12:53 AM

    Am I understanding this correctly: the code is never written to disk, but executed straight from memory?
  • 5 Mark Drew // Apr 7, 2009 at 12:39 PM

    @Martijn: That's right, but you use it as if it is in memory
  • 6 Adam Cameron // Jul 15, 2009 at 8:40 PM

    Mark, where are the docs for this ramdisk functionality?

    --
    Adam
  • 7 Todd Rafferty // Jul 29, 2009 at 6:25 PM

    @Adam: There is no doc, ram:/// is just that easy to use, it's always there and make a mapping and use it? What information do you need on ram disk?
  • 8 Adam Cameron // Jul 30, 2009 at 2:02 AM

    Hi Todd
    Well even if that's the extent of the docs for it, then that's what should be documented. For one thing: I didn't even know that creating a mapping was the only way to use it, so that should have been documented. I would have thought I could simply use ram:///myFileHere.dat as a reference to a file for the likes of CFFILE and other file operations (as per CF9), but fair enough if not, I can see arguments both ways. This still needs to be documented though. Can it be used for ALL file operations? Whether yes or no, it needs to be documented. Are there any considerations at all for any potential uses of the ramdisk (like in CF9, one cannot put an Application.cfc in RAM)? Even if there are no such considerations... it needs to be documented (even if it's "unlike CF9...". Although I agree documenting differences to CF9 might be a bit "pre"). How do I find out how much space I'm using for RAM-based file storage? Using CFDIRECTORY? Should be documented. Or how about how much space is left to use (I presume there are such considerations)? What happens when this space runs out, and I continue to try to use more? Both should be documented. Is there a management console for it (for like browsing the files within it, etc)?

    You know: stuff like that. I don't think that equates to a great tome of documentation, but it still equates to SOME documentation requirements.

    If a system has a feature... it should be documented. Especially if it's not a feature CF implements, so one can't simply point the punters at Adobe's docs (which is what I understand Railo and New Atlanta generally do, which I think is a bit... err... "professionally suspect" from the outset, IMO).

    Anyhow, thanks for answering my question (it saves me some reading, if nothing else! ;-).

    The reason I was asking is that CF is implementing a similar thing, and some issues with their implementation have been presented, so I wanted to see what Railo does in similar situations, so as to possibly suggest CF does the same thing by way of product conformity (if the Railo solution seemed like the right way, obviously).

    But if there's nothing to go on, we can start with a clean sheet, which is cool.

    Cheers.

    --
    Adam
  • 9 Todd Rafferty // Jul 30, 2009 at 2:06 AM

    Adam, I understand. Btw, feel free to join the Railo Documentation mailing list and assist. We could use all the help we can get. Right now, we're in the middle of a "Guys, c'mon.. pick *3* tags and write up an example for it!"

    btw, CF9 has the ram:/// feature now. Wonder where they got that idea from.

    /hrm
  • 10 Adam Cameron // Jul 30, 2009 at 2:47 AM

    Hi Todd
    I'd like to continue this conversation re docs, but I am reluctant to co-opt Mark's blog to do so. Can you pls drop me a line on adam_junk@hotmail.com. Cheers.

    --
    Adam