I'm trying to cache an object returned after a 3rd party API call via HTTP. The API charges based on calls, so I'm trying to cache the information returned for some period of time.
However I don't seem to be able to get cache_set() to ever store anything. I've enabled "Cache pages for anonymous users" and "Cache blocks" in the performance configuration, as I read somewhere that the cache API may depend on those being set.
I'm using code inside a function called in hook_block_view():
$cache_key = 'custom_module'.$index;
$conditions = cache_get($cache_key);
if (!$conditions) { $conditions = API_CALL($index); cache_set($cache_key, $conditions, 'cache', REQUEST_TIME + (60 * 10)); //stores in cache table and expires after 10 minutes }
However this still results in an API call per page load with testing from a logged out browser. I added some minimal test code:
cache_set('testing','foo','cache',CACHE_PERMANENT);
var_dump(cache_get('testing'));
And the output is "bool(false)".
Looking in the database shows the 'cache' table is empty.
I'm about to start digging through the function calls being cache_set() to see what is happening, and intend to report back what I find. However if this is a common problem perhaps someone already has an answer?
cache_get('testing')->data == 'foo'
as expected. Your cache table shouldn't be empty (unless you're not using db cache) so it might suggest you have a custom/contrib module invalidating the cache on every page load