6

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()?

1
  • 4
    I know you're out there, @VictorIn.
    – Matt Stein
    Jun 27, 2014 at 1:54

1 Answer 1

6

You can delete a cache 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.

5
  • Thanks Ben! An array of keys seems to make way more sense.
    – Matt Stein
    Jun 27, 2014 at 13:23
  • glad you agree!
    – Ben Croker
    Jun 27, 2014 at 15:44
  • 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.
    – Matt Stein
    Jun 27, 2014 at 16:43
  • Has craft()->fileCache has been updated to just craft()->cache? Feb 9, 2015 at 3:30
  • No, it is one of the available caching methods: buildwithcraft.com/classreference/etc/cache/FileCache
    – Ben Croker
    Feb 9, 2015 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.