Wikia/app — pull request #5045 by garthwebb (2014-10-15 18:55:10+00:00)
Title: New files implementing an asynchronous cache.

A class implementing an asynchronous cache. That is, if a cache value was found in the cache, but it is expired, this stale value will be returned and an asynchronous task will be started to regenerate the cache value. This eliminates the cache MISS time penalty for most cases.

Also included is a test script for this class. Example usage:
```shell
php ./asyncCache.php --get animal --ttl 20 --regen-ttl 10 --generate-args cat,5
```
This will fetch the key 'animal' setting a TTL of 20 seconds if it has to be regenerated and cached. It will serve stale data for 10 seconds (--regen-ttl) if the cache is found but stale and the asynchronous job has not completed. It will call the default test function 'AsyncCacheTestGenerator::getValue' with arguments 'cat' and 5. Here 'cat' is the value to store and 5 is the number of seconds the job should sleep to simulate an expensive request.

If this is run several times the output will show in what state the cache is in. Changing 'cat' to 'dog' will help show when stale values are being served while the 5 second regeneration job runs.

Additional parameters are available to test the other functionality of AsyncCache and are described via:
```shell
php ./asyncCache.php --help
```