Digging Deeper
Cache
Introduction
JCC Express MVC ships with a Laravel-style cache API.
Core capabilities:
- Multiple stores (
memory,file,redis) - Key/value operations (
get,put,forget,has) - Batch operations (
many,putMany) - Numeric ops (
increment,decrement) - Helpers (
remember,rememberForever,pull,add) - Tag-based invalidation (
tags([...]).flush()) - Static facade usage via
CacheFacade(aliased asCachefromjcc-express-mvc/Core/Cache)
Configuration and bootstrapping
Cache is configured in app/Config/cache.ts and merged in app/Config/index.ts.
At runtime, CacheServiceProvider reads app.config.cache and initializes the cache singleton.
TypeScript
You can still call Cache.getInstance(customConfig) manually (useful in tests), but for app runtime prefer provider-driven config.
Basic operations
TypeScript
Remember helpers
TypeScript
remember only runs the callback when the key is missing.
Numeric and atomic-style helpers
TypeScript
Batch operations
TypeScript
Tagged cache
Tagged keys are namespaced and can be flushed by tag group:
TypeScript
Store selection
Use the default store or explicitly pick one:
TypeScript
Driver notes
memoryis process-local (fast, reset on restart).redisserializes payloads as JSON and supports TTL withsetEx.- Invalid inputs throw explicit errors (missing key, null value, invalid TTL, etc.).
Summary
- Configure stores in
app/Config/cache.tsand letCacheServiceProviderinitialize cache. - Use the facade (
jcc-express-mvc/Core/Cache) forget/put/rememberconvenience. - Use
tags(...)when invalidation needs grouping. - Prefer
redisfor shared cache across processes/instances.