How does a plugin make use of Craft's storage? I am building a plugin that needs to cache generated images into a directory in Craft, presumably the craft/storage directory. I took a glance in the docs, but couldn't find much in the form of how to use storage. When building similar functionality in EE I used the their cache directory, so looking for something similar with Craft.

So how does one cache generated files in local directory so they can be used later to prevent the overhead of constantly having to generate the image?
craft/storage/ is used for all sorts of things, so there’s no single API for storing things in there. Mostly you would just be working with PHP’s standard IO functions like file_put_contents(). There are some handy functions in Craft’s IOHelper class too.

You can get the path to the storage folder via PathService::getStoragePath():



$storagePath = craft()-&gt;path-&gt;getStoragePath();


IOHelper::ensureFolderExists() is a handy function for creating a subfolder for your plugin within craft/storage:

$myStoragePath = $storagePath.'myplugin/';
IOHelper::ensureFolderExists($myStoragePath);