Answers.Body: <p>I found the corresponding reference page here:</p>
  
  <p><a href="https://docs.civicrm.org/dev/en/latest/framework/cache/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/cache/</a></p>
  
  <p>Looks straightforward:</p>
  
  <ol>
  <li>Set a cache value with Civi::cache()->set('mykey', 'myvalue');</li>
  <li>Get a cached value with Civi::cache()->get('mykey'); </li>
  <li>Delete a cached value with Civi::cache()->delete('mykey');</li>
  <li>Flush the entire cache with Civi::cache()->flush();</li>
  </ol>
  
  <p>As far as I know, the civicrm caching schema is pretty simple, there's just one key/value table.</p>
  
  <p>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!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-11T15:57:58.187Z
Answers.Text: 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.
Answers.UserDisplayName: mickadoo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-12T15:34:01.363Z
Answers.Text: 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.
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-20T14:07:00.913Z
Answers.LastActivityDate: 2017-12-12T15:31:43.840Z
Answers.LastEditDate: 2017-12-12T15:31:43.840Z
Answers.UserDisplayName: Alan Dixon
Body: <p>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?</p>
  
Tags: <extension><developer><cache>
Title: How can I use CiviCRM's cache table?
ThreadText: # How can I use CiviCRM's cache table?
  
  (Asked by: username_0 on 2015-10-28)
  
  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?
  
  **Tags:** extension, developer, cache
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-04-20. Score: 4
  
  I found the corresponding reference page here:
  
  <https://docs.civicrm.org/dev/en/latest/framework/cache/>
  
  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!
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: 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.  
  
  ---
  
  