I have a rather expensive server call that I need to cache for 30 seconds. It seems, however, that I cannot get the cache expiration date.
In the code below, after the first half-time of caching, it will never pass $ return-> cache_data even after a time of () + 30 seconds.
Notice, I can even print $ cache-> expire, and it is definitely set to the time elapsed 30 seconds ago and is never updated.
I manually cleared the cache many times to confirm that I am getting the same results.
Is something wrong with this?
function mymodule_get_something($id) { // set the unique cache id $cid = 'id-'. $id; // return data if there an un-expired cache entry // *** $cache ALWAYS gets populated with my expired data if ($cache = cache_get($cid, 'cache_mymodule')) { return $cache->data; } // set my super expensive data call here $something = array('Double Decker Taco', 'Burrito Supreme'); // set the cache to expire in 30 seconds cache_set($cid, $something, 'cache_mymodule', time() + 30); // return my data return $something; }
source share