One of the great new features in ColdFusion 9 that I haven't seen much press about is it's Virtual File System. The virtual file system is essentially a RAM disk (remember back to DOS?). This allows you to do three really cool things. First. you can now write files such as images, spreadsheets, etc. to memory instead of disk before serving them back to the browser. Here's an example from the beta docs that shows this in use for writing a JPG file to memory and serving it up:
The second thing this lets you do is write dynamic .cfm files to memory and execute them. Again from the beta docs, to write a file you would do something like this:
How you use/execute an in-memory file depends on whether the tag/function you are using requires a relative or absolute path. For tags/functions that require a relative path, you need to first create a mapping for ram:// in the ColdFusion Administrator. Once you've done that, you simple use the mapping in the relative URL. For example if you create a mapping called /inmemory, you would use it within cfinclude like this:
For tags/functions that take an absolute path, the syntax is straightforward. From the beta docs:
The third thing you can do with the virtual file system is write and execute CFCs in memory. To write a CFC to the virtual file system you do the following, from the beta docs:
You execute the CFC like so:
There are some limitations to the ram based file system. First and foremost, you can't write Application.cfm or Application.cfc to memory. Additionally, paths are case-sensitive.
The full list of tags that support the virtual file system are as follows:
Supported file functions:
So, what do you all think? I think this opens up a lot of interesting possibilities, especially in terms of performance improvement.
Nice to CF catching up! ;)
You asked where this would be useful. One case I can think of in the project I work on (MXUnit) relates to testing private functions. When you want to test private functions you can use a function in mxunit called makePublic(). Under the hood, this generates a new .cfc on the fly, writes it to disk, and then does a createObject() on that thing. This new virtual file system would be nice to use for this, since it wouldn't require disk IO or cleanup.
Good stuff.
Is it cleared after the request ?
Can it be shared between application ?
@Bjorn, the virtual file system exists until you manually delete it. I'll do a follow up post on this...
Check out <a href="http://www.brooks-bilson.com/blogs/rob/index.cfm/2... follow-up post</a> which should address most of those questions.