Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-27T22:33:55.497Z
Answers.Text: Would FileCache be a recommended method? And do you normally save data as JSON?
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-27T22:47:56.473Z
Answers.Text: 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.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-27T22:17:56.347Z
Answers.LastActivityDate: 2014-10-27T22:17:56.347Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <plugin-development><performance><caching>
Title: Use cache instead of saving to database
ThreadText: # 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.  
  
  ---
  
  