Seeking reviews for an improvement to Memcache's time-based expiration/invalidation logic

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
DamienMcKenna's picture

Hello there.

While working on a large site a coworker discovered that there was a problem with the Memcache module's cache clearing and time-based expiration & invalidation.

My coworker devised a very simple scenario that tested what the Memcache module was doing:

  1. Store some data in the cache via cache_set($data, $cid).
  2. Verify what data is contained in the cache using cache_get($cid).
  3. Clear the entire cache bin via cache_clear_all('*', $bin, TRUE).
  4. Try loading the same cache object via cache_get($cid), verify that the object doesn't exist.
  5. Store new data in the cache via cache_set($data, $cid2).
  6. Verify what data is contained in the cache using cache_get($cid2).

With Memcache 7.x-1.5 and the current -dev release (7.x-1.5+3-dev) the third cache_get() fails to return any data.

The problem is that the code is as follows: if a cache_clear_all() occurs on any page request that includes a cache_get(), the logic is not able to differentiate between cached objects which were created before or after the cache_clear_all(). This happens because it uses seconds (in the form of a UNIX timestamp via the time() function) as its discrete unit, and obviously on any sort of modern computer you can be pretty much guaranteed to have a cache_get() happen during the same second as a cache_clear_all().

After a few hours' of debugging and testing I put together a patch that changes all of the module's logic to work off milliseconds via the microtime() function which has been a standard part of PHP since the v4 days. Using the patch the simple test scenario finally works correctly - the first cache_get() has data, the second is empty, the third has data.

I'm writing this to let you know about this patch, and to ask for help in testing it. I'm going to continue working on fixing the simpletests, but obviously the more help the faster we'll get through it.

https://www.drupal.org/node/2543030

Thanks.

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week