tags:

views:

13

answers:

0

I have a setup that uses a method called update in a cache class. It simply creates an array using a key-value pair. For example, if I do $cache->update('cache_key', 'array_key', 'array_value');, that will result in an array a key as array_key with a value of array_value. If I then issue another update using the same cache key, but a different array_key, it will append it to that cache_key's array. If, however, the array_key is the same, it just changes the value of that key. It then will call apc_store to put it in the cache. The issue I am having is that apc_store doesn't seem to be replacing the cached item within the same script execution. I have to end the script then start it again for the cache to be able to change. What I have:

$registry->log('Update result before: ', $cache->update('TEST', 'key', mc36()));
$registry->log('Value before: ', $cache->get('TEST'));

sleep(1);

$registry->log('Update result after: ', $cache->update('TEST', 'key', mc36()));
$registry->log('Value after: ', $cache->get('TEST'));

All mc36() is return a timestamp in base 36. The result:

2010-07-01 20:25:14 (*:Travis): 'Update type for TEST: replace'
2010-07-01 20:25:14 (*:Travis): 'Update result before: '
2010-07-01 20:25:14 (*:Travis): true
2010-07-01 20:25:14 (*:Travis): 'Value before: '
2010-07-01 20:25:14 (*:Travis): array (
    'key' => '19av8nt2nq',
)
2010-07-01 20:25:16 (*:Travis): 'Update type for TEST: replace'
2010-07-01 20:25:16 (*:Travis): 'Update result after: '
2010-07-01 20:25:16 (*:Travis): false
2010-07-01 20:25:16 (*:Travis): 'Value after: '
2010-07-01 20:25:16 (*:Travis): array (
  'key' => '19av8nt2nq',

)

apc_store is returning false the second time, but if the script is restarted, the value is able to change; only for the first update of course.

Anyway to fix this or get around this without resorting to deleting the key then adding it back?