Improve caching behavior
Application caching based upon the Stash library has several issues/problems/shortcomings:
1. When using the file-based cache race conditions can cause individual cache files to be corrupted. Since the cache files contain executable PHP code, subsequent loading causes fatal syntax errors. There is no Stash-provided fix for this issue.
2. When using the file-based cache abrupt loss of session can occur due to race conditions.
3. Garbage collection of the cache is partially broken, resulting in cache overflows and when using the file-based cache periodic high-CPU load and unresponsiveness.
4. Garbage collection happens randomly and in-process, which results in unpredictable GC frequency and hangs when large amounts of cache garbage is to be collected.
Solution for #4: add CLI caUtils option to perform garbage collection. Add option to trigger GC from queue processing as periodic task.
Solution for #3: update GC routines to properly evaluate expiration data in new JSON-based cache encoding; limit number of files to be evaulated in-process.
Solution for #2: loss of session appears to be tied to session loading behavior and subsequent end-of-request save when a routing error occurs. Preventing session saves on routing errors should resolve this.
Solution for #1: implement JSON-based cache file format. This will eliminate syntax errors and the dubious security implications of having cached data in an executable format. If JSON is written corruptly to the cache it will be considered a cache miss rather than a fatal error.