Answers.Body: <p>You can <a href="http://www.yiiframework.com/doc/api/1.1/CCache#delete-detail">delete a cache</a> as follows:</p>
  
  <pre><code>craft()-&gt;fileCache-&gt;delete($key);
  </code></pre>
  
  <p>So instead of caching individual keys, you could perhaps cache an array of keys and delete the entire array when you want to clear out your keys.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T13:23:14.660Z
Answers.Text: Thanks Ben! An array of keys seems to make way more sense.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T15:44:00.460Z
Answers.Text: glad you agree!
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T16:43:29.820Z
Answers.Text: You've given me the concept of a multi-dimensional cache *and* Guzzle this week. I can't even imagine what next week has in store.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-09T03:30:17.357Z
Answers.Text: Has `craft()->fileCache` has been updated to just `craft()->cache`?
Answers.UserDisplayName: Ben Parizek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-09T09:18:39.860Z
Answers.Text: No, it is one of the available caching methods: http://buildwithcraft.com/classreference/etc/cache/FileCache
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T11:07:32.083Z
Answers.LastActivityDate: 2014-06-27T11:07:32.083Z
Answers.UserDisplayName: Ben Croker
Body: <p>I'm building a plugin to browse store orders via a third-party API. I make various requests to URLs that can include query parameters:</p>
  
  <ul>
  <li><code>/customers</code></li>
  <li><code>/orders/e8b48e72-9c7f-4d6f-91aa-2f7238bdf936</code></li>
  <li><code>/orders?offset=0&amp;limit=250&amp;from=2014-05-26T22%3A58%3A38%2B00%3A00&amp;to=2014-06-26T22%3A58%3A38%2B00%3A00</code></li>
  </ul>
  
  <p>I've just started using Guzzle and more importantly <code>craft()-&gt;fileCache</code> to keep results around for a few minutes and speed up browsing. I use the query URI as the key for the cache:</p>
  
  <pre><code> craft()-&gt;fileCache-&gt;set($query, $response-&gt;getBody(true), 600); // store result for 10 minutes
  </code></pre>
  
  <p>A web hook gets hit with every new order that comes in, making it an ideal time to clear out these caches I've set—but I have no idea <em>how</em>.</p>
  
  <p>Is there any way I can tag this plugin's caches or somehow clear out only those I've made, rather than get overzealous with <code>craft()-&gt;fileCache-&gt;flushValues()</code>?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-27T01:54:46.027Z
Comments.Text: I know you're out there, @VictorIn.
Comments.UserDisplayName: Matt Stein
Tags: <plugin-development><cache>
Title: What's the best way to clear cached JSON responses from a third-party API?
ThreadText: # What's the best way to clear cached JSON responses from a third-party API?
  
  (Asked by: username_0 on 2014-06-26)
  
  I'm building a plugin to browse store orders via a third-party API. I make various requests to URLs that can include query parameters:
  
  * `/customers`
  * `/orders/e8b48e72-9c7f-4d6f-91aa-2f7238bdf936`
  * `/orders?offset=0&limit=250&from=2014-05-26T22%3A58%3A38%2B00%3A00&to=2014-06-26T22%3A58%3A38%2B00%3A00`
  
  I've just started using Guzzle and more importantly `craft()->fileCache` to keep results around for a few minutes and speed up browsing. I use the query URI as the key for the cache:
  
  ```
   craft()->fileCache->set($query, $response->getBody(true), 600); // store result for 10 minutes
  
  ```
  
  A web hook gets hit with every new order that comes in, making it an ideal time to clear out these caches I've set—but I have no idea *how*.
  
  Is there any way I can tag this plugin's caches or somehow clear out only those I've made, rather than get overzealous with `craft()->fileCache->flushValues()`?
  
  **Tags:** plugin-development, cache
  
  > **Comments:**
  > **username_0**: I know you're out there, @VictorIn.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-27. Score: 6 | Accepted answer
  
  You can [delete a cache](http://www.yiiframework.com/doc/api/1.1/CCache#delete-detail) as follows:
  
  ```
  craft()->fileCache->delete($key);
  
  ```
  
  So instead of caching individual keys, you could perhaps cache an array of keys and delete the entire array when you want to clear out your keys.
  
  > **Comments:**
  > **username_0**: Thanks Ben! An array of keys seems to make way more sense.  
  > **username_1**: glad you agree!  
  > **username_0**: You've given me the concept of a multi-dimensional cache *and* Guzzle this week. I can't even imagine what next week has in store.  
  > **username_2**: Has `craft()->fileCache` has been updated to just `craft()->cache`?  
  > **username_1**: No, it is one of the available caching methods: http://buildwithcraft.com/classreference/etc/cache/FileCache  
  
  ---
  
  