When developing an extension, I'd like to cache some data to avoid the expense of re-calculating it. Is there a civicrm version of the Drupal's caching interface for developers?

1 Answer 1


I found the corresponding reference page here:


Looks straightforward:

  1. Set a cache value with Civi::cache()->set('mykey', 'myvalue');
  2. Get a cached value with Civi::cache()->get('mykey');
  3. Delete a cached value with Civi::cache()->delete('mykey');
  4. Flush the entire cache with Civi::cache()->flush();

As far as I know, the civicrm caching schema is pretty simple, there's just one key/value table.

As an aside - I just discovered that Herb @ freeform has contributed a recent patch for using Redis as the cache backend. I'm a Redis fan also, so thanks Herb!

  • So Civi::cache is an in-memory cache? It's a bit confusing since I saw the civicrm_cache table and would expect the cache to use that. I was hoping to use this to persist data between requests instead of implementing it myself.
    – mickadoo
    Commented Dec 11, 2017 at 15:57
  • No, the caching mechanism is abstracted and persistent - it might be using Redis for performance, but the canonical implementation is indeed that civicrm_cache table. But it's not designed for user session data, it's for configuration type data.
    – Alan Dixon
    Commented Dec 12, 2017 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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