Runtime Cache
Keep cache logic in services, not controllers.Runtime setup
Environment behavior
APP_ENV=development: memory cacheAPP_ENV=staging: file cache usingCACHE_DIRAPP_ENV=production: Memcached, then file cache, then memory cache
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Cache behavior at the service boundary, environment selection, and read-through invalidation patterns.
import { CacheManager, setupCache } from "@alpha.consultings/eloquent-orm.js";
setupCache();
APP_ENV=production
MEMCACHED_HOST=127.0.0.1
MEMCACHED_PORT=11211
CACHE_DIR=.cache
APP_ENV=development: memory cacheAPP_ENV=staging: file cache using CACHE_DIRAPP_ENV=production: Memcached, then file cache, then memory cacheasync function activeUsers() {
const key = "users:active:v1";
const cached = await CacheManager.get(key);
if (cached) return cached;
const users = await User.where("is_active", true)
.orderBy("created_at", "desc")
.limit(20)
.get();
await CacheManager.set(key, users, 60);
return users;
}
async function createUser(data: Record<string, unknown>) {
const created = await User.create(data);
await CacheManager.delete("users:active:v1");
return created;
}
eloquent cache:stats
eloquent cache:clear