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?

1 Answer 1


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()->path->getStoragePath();

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

$myStoragePath = $storagePath.'myplugin/';
  • Awesome, I kinda figured that may be the case, I just wanted to check before I wrote the code. Commented Aug 15, 2014 at 16:36
  • 1
    One other quick question, is there was way to serve the images that I am saving in storage on the front-end? Is there way to generate a url to that? I am thinking there isn't a way since it's above web root. Anyway you can think of to get around that? Commented Aug 15, 2014 at 16:48
  • @JustinKimbrell Probably warrants a new question :) Commented Aug 15, 2014 at 16:49
  • It did: craftcms.stackexchange.com/questions/1952/…
    – Ole
    Commented Apr 9, 2021 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.