Caching
DevPortal provides a unified cache API that works across file, Redis, and Memcached drivers.
Cache Drivers
| Driver | Config value | Best for |
|---|---|---|
| File | file | Local dev, simple deployments |
| Redis | redis | Production, shared cache |
| Memcached | memcached | High-throughput, simple key/value |
| Array | array | Testing (in-memory, no persistence) |
Basic Usage
use DevPortal\Cache;
// Store for 60 minutes
Cache::put('user:42', $user, ttl: 3600);
// Retrieve (returns null if missing)
$user = Cache::get('user:42');
// Remember pattern — fetch & cache in one call
$posts = Cache::remember('posts:all', 3600, function () {
return Post::all();
});
// Forget
Cache::forget('user:42');
// Flush everything
Cache::flush();
Cache Tags
Tags let you group and invalidate related keys at once (Redis/Memcached only):
Cache::tags(['posts', 'user:42'])->put('feed', $feed, 3600);
// Invalidate all "posts" cache
Cache::tags('posts')->flush();
✅ Best Practice
Use the
remember() pattern over separate get/put calls — it's atomic and avoids cache stampedes.