Description
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.x |
The FilesystemAdapter
implementation for Symfony/Cache
doesn't seem to have any mechanisms to constrain the used cache size, auto-purging cache entries by least-recently-used, or their expiry date. Most other adapters (e.g. PHP's opcache, memcache) handle this internally. The filesystem adapter clears out expired caches on access only. While you can technically avoid causing the webserver filesystem to overflow by designating a limited filesystem partition for your temp folder, that's not a very common practice - and hence will leave users of this library quite exposed to server capacity exhaustion.
The StashPHP cache library has implemented a purge() action for this purpose (implementation details):
The Purge function allows drivers to perform basic maintenance tasks, such as removing stale or expired items from storage. Not all drivers need this, as many interact with systems that handle that automatically. It's important that this function is not called from inside a normal request, as the maintenance tasks this allows can occasionally take some time.
Zend_Cache used to deal with this by randomly calling a purge action every 100 cache accesses through the library - which makes app performance less predictable, but means you don't need to worry about cron jobs etc.
In general, there's not enough metadata to create a least-recently-used purge. The filesystem adapter uses touch() to set expiry metadata, but doesn't deal with last access.
If you consider this to be out of scope for the library itself, would you be open to a pull request which documents this fairly significant gotcha for the filesystem driver?