Caching#
DBLayer caching is powered by infocyph/cachelayer.
DB::cache() returns a CacheLayer cache instance (PSR-6 + PSR-16 style API).
Basic Cache#
$cache = DB::cache();
$cache->set('k', 'v', 60);
$value = $cache->get('k');
TTL is in seconds. Use null for adapter default.
File Cache Adapter#
$cache = DB::useFileCache(__DIR__ . '/../storage/cache');
Use file adapter when you need durable local cache without external services.
Remember Pattern#
$rows = $cache->remember('users:active', function () {
return DB::table('users')->where('active', '=', 1)->get();
}, 120);
The resolver return value is cached as-is, including null.
Operational Metrics#
CacheLayer exposes adapter-level metrics:
$metrics = DB::cache()->exportMetrics();