-
-
Notifications
You must be signed in to change notification settings - Fork 0
Cache invalidation
FileCache uses time-based invalidation.
Each Cache instance is constructed with a lifetime in seconds. Once a cached entry is older than that lifetime, it is treated as invalid and the next read will regenerate it through the callback.
use GT\FileCache\Cache;
$cache = new Cache(
__DIR__ . "/cache",
60 * 30
);In this example, every entry created by that Cache instance remains valid for 30 minutes.
If no lifetime is provided, the default is 1 hour.
There is no background cleanup job and no proactive refresh process in the library. Invalidation happens when we attempt to read a key:
- FileCache checks whether the cache file exists.
- FileCache compares the file modification time with the configured lifetime.
- If the entry is too old, the callback is executed to generate a replacement value.
This keeps the implementation simple and means expired entries are only refreshed when they are actually needed again.
The high-level Cache API exposes invalidate() for removing one cached entry by key:
$cache->invalidate("user:105:profile");This deletes the stored cache file for that key if it exists. If the key is already missing, the call has no effect.
The next time that key is requested through get() or any typed getter, the callback will run again to repopulate the cache.
For lower-level control, the library also includes GT\FileCache\FileAccess, which exposes:
getData()setData()checkValidity()invalidate()
That class is also the optional third constructor argument to Cache, so applications with custom cache management requirements can work at the lower level when needed.
For details on how keys map to filenames on disk, continue with Cache keys and storage.
PHP.GT/FileCache is a separately maintained component of PHP.GT/WebEngine.