Answers.Body: <p>Craft is piggybacking off of Yii's <a href="http://www.yiiframework.com/doc/guide/1.1/en/caching.overview" rel="nofollow">caching functionality</a> for 99% of this and their cache classes don't expose any type of TTL functionality.  My guess is that because of all the different caching providers they support (memcache, xCache, WinCache, ApcCache, etc.), it looks like Redis is the only one that has this sort of functionality.</p>
  
  <p>There isn't a clean way for us to add this to Craft itself, so I think a proper fix would be to add it to Yii, but considering Yii 1 is in bug fix more and not getting any more enhancements and Yii 2 has <a href="http://www.yiiframework.com/doc-2.0/guide-caching-data.html" rel="nofollow">dropped support</a> for Redis, that seems unlikely.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-22T21:55:35.787Z
Answers.LastActivityDate: 2016-01-22T21:55:35.787Z
Answers.UserDisplayName: Brad Bell
Body: <p>Is it possible to find the seconds left / TTL when retrieving cache (when set to Redis) via plugins? I'm using short-lived cache (~600 seconds) to put users on "cooldown" to limit how often they can create new forum topics, by creating a user-specific cache whenever they create a topic. Then I can check and see if this cache exists when they create a new topic.</p>
  
  <p>When getting the cache like:</p>
  
  <pre><code>$cache = craft()-&gt;cache-&gt;get( $cacheKey );
  </code></pre>
  
  <p>If it returns true (exists,) I'd like to be able to tell the user how long they need to wait until they can post again (like Reddit.)</p>
  
  <p>I've tried methods like</p>
  
  <pre><code>$cache-&gt;ttl; // doesn't work; not an object
  $cache['ttl']; // doesn't work, no 'ttl' key
  </code></pre>
  
  <p>Maybe I am missing something in the <a href="https://craftcms.com/classreference/services/CacheService" rel="nofollow">Cache Service Doc</a>? Or is this meta information simply not available?</p>
  
  <p>Any information would be awesome. Cheers! </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-22T20:52:40.977Z
Comments.Text: Just shot them an email. Cheers!
Comments.UserDisplayName: taylor
Tags: <plugin-development><cache><php>
Title: Craft Redis Cache - Get Time Left?
ThreadText: # Craft Redis Cache - Get Time Left?
  
  (Asked by: username_0 on 2016-01-22)
  
  Is it possible to find the seconds left / TTL when retrieving cache (when set to Redis) via plugins? I'm using short-lived cache (~600 seconds) to put users on "cooldown" to limit how often they can create new forum topics, by creating a user-specific cache whenever they create a topic. Then I can check and see if this cache exists when they create a new topic.
  
  When getting the cache like:
  
  ```
  $cache = craft()->cache->get( $cacheKey );
  
  ```
  
  If it returns true (exists,) I'd like to be able to tell the user how long they need to wait until they can post again (like Reddit.)
  
  I've tried methods like
  
  ```
  $cache->ttl; // doesn't work; not an object
  $cache['ttl']; // doesn't work, no 'ttl' key
  
  ```
  
  Maybe I am missing something in the [Cache Service Doc](https://craftcms.com/classreference/services/CacheService)? Or is this meta information simply not available?
  
  Any information would be awesome. Cheers!
  
  **Tags:** plugin-development, cache, php
  
  > **Comments:**
  > **username_0**: Just shot them an email. Cheers!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-22. Score: 1 | Accepted answer
  
  Craft is piggybacking off of Yii's [caching functionality](http://www.yiiframework.com/doc/guide/1.1/en/caching.overview) for 99% of this and their cache classes don't expose any type of TTL functionality. My guess is that because of all the different caching providers they support (memcache, xCache, WinCache, ApcCache, etc.), it looks like Redis is the only one that has this sort of functionality.
  
  There isn't a clean way for us to add this to Craft itself, so I think a proper fix would be to add it to Yii, but considering Yii 1 is in bug fix more and not getting any more enhancements and Yii 2 has [dropped support](http://www.yiiframework.com/doc-2.0/guide-caching-data.html) for Redis, that seems unlikely.
  
  
  ---
  
  