File-based cache driver — persists cached data to disk with automatic expiration and atomic writes.
composer require marko/cache-fileuse Marko\Cache\Contracts\CacheInterface;
class SettingsService
{
public function __construct(
private CacheInterface $cache,
) {}
public function getAll(): array
{
if ($this->cache->has('settings.all')) {
return $this->cache->get('settings.all');
}
$settings = $this->loadFromDatabase();
$this->cache->set('settings.all', $settings, ttl: 7200);
return $settings;
}
}Full usage, API reference, and examples: marko/cache-file