# Save .jpeg in cache dir?

**URL:** <https://discourse.cakephp.org/t/save-jpeg-in-cache-dir/4461>\
**Category:** Need Help\
**Created:** [June 25, 2018, 10:09am UTC](https://discourse.cakephp.org/t/save-jpeg-in-cache-dir/4461 "2018-06-25T10:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [June 25, 2018, 10:09am UTC](https://discourse.cakephp.org/t/save-jpeg-in-cache-dir/4461/1 "2018-06-25T10:09:33Z")

</div>

In order to save some resources, I want to save watermarked images to the cache dir.  
Currently, I use PHP’s `file_exists` to check whether the image already has been watermarked, but my question is, is there a way to save this file using CakePHP’s `Cache` class?  
I want to save the file to `/tmp/cache/img/filename.jpeg` and load it from there as well once it has been saved.

---

<div class="post-metadata">

**Author:** ![Schlaefer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/schlaefer/32/1001_2.png) [@Schlaefer](https://discourse.cakephp.org/u/Schlaefer)\
**Post date:** [June 25, 2018, 10:48am UTC](https://discourse.cakephp.org/t/save-jpeg-in-cache-dir/4461/2 "2018-06-25T10:48:49Z")

</div>

Do you want to serve the pictures directly or through PHP?

Through PHP: just use the Cache class as with every other blob of data. Don’t bother with files, Cache will take care of that.

Directly: work with CakePHP’s File class and put them somewhere in the webroot folder.

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [June 25, 2018, 2:28pm UTC](https://discourse.cakephp.org/t/save-jpeg-in-cache-dir/4461/3 "2018-06-25T14:28:39Z")

</div>

I want to serve them through PHP preferably.  
Will using the Cache class clean-up itself when the disk get’s quite full?
