Aeros provides a flexible caching system that supports multiple drivers including Redis, Memcached, and local file storage. The cache system is configured in config/cache.php and accessed through the cache() helper function.
// Use Rediscache('redis')->set('key', 'value');// Use Memcachedcache('memcached')->add('event:listener', $eventClass);// Use local file cachecache('local')->set('config', $data);
The setConnection() method validates that the connection exists in your configuration. An exception will be thrown if you attempt to use an undefined connection.
When using Redis, you have access to all Predis client methods:
// String operationscache('redis')->set('key', 'value');cache('redis')->get('key');// Set with expiration (EX = seconds)cache('redis')->set('session:123', $data, 'ex', 3600);// Set only if not exists (NX)cache('redis')->set('lock:process', time(), 'ex', 10, 'nx');// List operationscache('redis')->lpush('queue', $job);cache('redis')->rpush('queue', $job);cache('redis')->lpop('queue');cache('redis')->blpop(['queue1', 'queue2'], 5);// Key pattern matching$keys = cache('redis')->keys('user:*');// Delete multiple keyscache('redis')->del(['key1', 'key2', 'key3']);
The local driver uses the file system for caching:
// Uses app()->file under the hoodcache('local')->write('cache/data.json', json_encode($data));$data = json_decode(cache('local')->read('cache/data.json'));
For queue operations, the Redis driver uses an infinite timeout to support blocking operations:
// Queue connections use timeout = 0 for BLPOP supportcache('queue')->blpop(['job:queue'], 0);
Connections with names containing ‘queue’ automatically use infinite timeout (0) instead of the default 1-second timeout, enabling blocking operations like BLPOP.
function getCachedUser($userId) { // Try local cache first (fastest) if ($user = cache('local')->read("cache/user_{$userId}.json")) { return json_decode($user, true); } // Try Redis (fast) if ($user = cache('redis')->get("user:{$userId}")) { // Store in local cache for next time cache('local')->write("cache/user_{$userId}.json", json_encode($user)); return $user; } // Fetch from database (slow) $user = db()->query("SELECT * FROM users WHERE id = ?", [$userId]); // Cache in both layers cache('redis')->set("user:{$userId}", $user, 'ex', 3600); cache('local')->write("cache/user_{$userId}.json", json_encode($user)); return $user;}