Answers.Body: <p>You want to take a look at the <code>CacheService</code> class which is the service that allows you to programmatically interact with the internal cache.</p>
  
  <p>This is an example of how to set some cache that expires in 3600 seconds (one hour). Set the expiration to 0 if you never want it to expire.</p>
  
  <pre><code>craft()-&gt;cache-&gt;set('some_key', 'some_value', 3600);
  </code></pre>
  
  <p>Just checkout <code>CacheService</code> for more details, as there are more methods and parameters to make use of, but this should be the basic use case.</p>
  
  <p><a href="https://docs.craftcms.com/api/v2/craft-cacheservice.html" rel="nofollow noreferrer">CacheService Class Reference</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-01-14T16:57:57.933Z
Answers.LastActivityDate: 2019-03-13T22:12:43.953Z
Answers.LastEditDate: 2019-03-13T22:12:43.953Z
Answers.UserDisplayName: Justin Kimbrell
Body: <p>I have a plugin that makes several and potentially slow database calls that eventually return 8 Entries. Is there a way to make use of Craft's built in caching on the plugin side? Using the {% cache %} tag doesn't seem to be doing the trick. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-14T16:55:37.617Z
Comments.Text: Are you referring to caching from one of your plugin's templates or caching from PHP code?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-14T20:52:16.450Z
Comments.Text: Caching from PHP code. The plugin does not have a template, just returns a set of Entries from a variable.
Comments.UserDisplayName: Aaron Berkowitz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-14T20:53:06.257Z
Comments.Text: Then Justin's [answer](http://craftcms.stackexchange.com/a/6585/57) is spot on.
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><cache>
Title: Cacheing in PHP code for plugin
ThreadText: # Cacheing in PHP code for plugin
  
  (Asked by: username_0 on 2015-01-14)
  
  I have a plugin that makes several and potentially slow database calls that eventually return 8 Entries. Is there a way to make use of Craft's built in caching on the plugin side? Using the {% cache %} tag doesn't seem to be doing the trick.
  
  **Tags:** plugin-development, cache
  
  > **Comments:**
  > **username_1**: Are you referring to caching from one of your plugin's templates or caching from PHP code?  
  > **username_0**: Caching from PHP code. The plugin does not have a template, just returns a set of Entries from a variable.  
  > **username_1**: Then username_2's [answer](http://craftcms.stackexchange.com/a/6585/57) is spot on.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-01-14. Score: 8 | Accepted answer
  
  You want to take a look at the `CacheService` class which is the service that allows you to programmatically interact with the internal cache.
  
  This is an example of how to set some cache that expires in 3600 seconds (one hour). Set the expiration to 0 if you never want it to expire.
  
  ```
  craft()->cache->set('some_key', 'some_value', 3600);
  
  ```
  
  Just checkout `CacheService` for more details, as there are more methods and parameters to make use of, but this should be the basic use case.
  
  [CacheService Class Reference](https://docs.craftcms.com/api/v2/craft-cacheservice.html)
  
  
  ---
  
  