opencart/opencart — pull request #1403 by dolorian (2014-05-06 19:17:24+00:00)
Title: File cache driver cleanup and optimization

1. Replaced fopen(), fwrite() and fclose() with file_put contents to avoid race conditions when writing the file contents. Currently an exclusive lock is not acquired which could cause unexpected errors when multiple php threads try to save the same file.

2. Cache cleanup optimization. Currently a cleanup (glob on all files in cache floder) is executed in __construct() on every request, which is not necessary and is more or less a performance penalty (especially when having thousands of cache files, which is the case with some extensions). I added a condition, so the cleanup is executed randomly based on probability. It's currently 1/4, but it is configurable. I added an additional check in get() method so you don't fetch expired cache data before it has been purged.

3. I added $expire argument to the set() method, which makes it easy to cache
data with custom expire time without having to make a new cache class instance.