<
⌘K
GitHub v2.4.0

Caching

DevPortal provides a unified cache API that works across file, Redis, and Memcached drivers.

Cache Drivers

DriverConfig valueBest for
FilefileLocal dev, simple deployments
RedisredisProduction, shared cache
MemcachedmemcachedHigh-throughput, simple key/value
ArrayarrayTesting (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.
<