<p><code>craft()-&gt;cache</code> can point to any one of several different caching drivers as defined by the   <a href="http://buildwithcraft.com/docs/config-settings#cacheMethod" rel="nofollow">cacheMethod</a> config setting.</p>

<p>The available methods are all pretty much stock <a href="http://www.yiiframework.com/doc/api/1.1/#system.caching" rel="nofollow">Yii provided caching drivers</a>, with the exception of <a href="http://buildwithcraft.com/classreference/etc/cache/FileCache" rel="nofollow">FileCache</a>, which we've <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/cache/FileCache.php" rel="nofollow">extended a bit</a>.</p>

<p>Note that FileCache is used by default and its values are saved under the <code>craft/storage/runtime/cache</code> folder.</p>

CC BY-SA 3.0
2014-10-27T22:33:55.497Z
Would FileCache be a recommended method? And do you normally save data as JSON?
a-am
CC BY-SA 3.0
2014-10-27T22:47:56.473Z
It's the simplest and most general purpose, but it really depends on the context.  You can save whatever you want in there. Yii/Craft does it's own serialization to the contents before writing it to the file, anyway.
Brad Bell
CC BY-SA 3.0
2014-10-27T22:17:56.347Z
2014-10-27T22:17:56.347Z
Brad Bell
<p>With my plugin I am generating and saving a lot of data to a secondary table. Data that can be generated on the fly that is associated with entries. I have noticed a performance hit and was given a suggestion of caching some of that data instead of writing to a database.  </p>

<p>Does craft have a built in caching system I can use for accomplishing something like this?</p>

<plugin-development><performance><caching>
Use cache instead of saving to database
# Use cache instead of saving to database

(Asked by: username_0 on 2014-10-27)

With my plugin I am generating and saving a lot of data to a secondary table. Data that can be generated on the fly that is associated with entries. I have noticed a performance hit and was given a suggestion of caching some of that data instead of writing to a database.

Does craft have a built in caching system I can use for accomplishing something like this?

**Tags:** plugin-development, performance, caching


---

## 1 answers

### Answer by username_1 on 2014-10-27. Score: 3 | Accepted answer

`craft()->cache` can point to any one of several different caching drivers as defined by the [cacheMethod](http://buildwithcraft.com/docs/config-settings#cacheMethod) config setting.

The available methods are all pretty much stock [Yii provided caching drivers](http://www.yiiframework.com/doc/api/1.1/#system.caching), with the exception of [FileCache](http://buildwithcraft.com/classreference/etc/cache/FileCache), which we've [extended a bit](https://github.com/pixelandtonic/Craft-Release/blob/master/app/etc/cache/FileCache.php).

Note that FileCache is used by default and its values are saved under the `craft/storage/runtime/cache` folder.

> **Comments:**
> **username_0**: Would FileCache be a recommended method? And do you normally save data as JSON?  
> **username_1**: It's the simplest and most general purpose, but it really depends on the context.  You can save whatever you want in there. Yii/Craft does it's own serialization to the contents before writing it to the file, anyway.  

---

