cache_get()
is not working as expected when called in a request initiated by drupal_http_request()
on the same server. Is it true that the cache_set()
immediately before drupal_http_request()
doesn't actually take place in the database until the first database transaction is committed?
Given the sequence:
cache_set($cid, $data)
cache_get($cid)
// returns data- external request using
drupal_http_request()
cache_get($cid)
// same $cid, returns FALSE
cache_get($cid)
// of course, returns data
To make the cached item available to the request initiated by drupal_http_request()
I wrapped the cache_set call in a function like this, but it had no effect.
function cache_set_wrapper($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) {
$txn = db_transaction();
return cache_set($cid, $data, $bin, $expire);
}
Why is there a discrepancy in the cache between the initial request on the second request?
hook_node_insert()
. So my transaction is started after the one for the node. Mine goes out of scope first, but does it get executed before the node_insert transaction is executed? – htoip Jul 26 '14 at 21:59