Skip to content

ModularousCache ​

Facade: Unusualify\Modularous\Facades\ModularousCache
Accessor: modularous.cache
Underlying: Unusualify\Modularous\Services\ModularousCacheService

Full cache facade for Modularous — handles tag-based caching, TTL management, and targeted cache invalidation scoped to modules and route names. See ModularousCacheService for implementation details.

Methods ​

Configuration ​

MethodSignatureDescription
getDriver(): stringReturns the active cache driver name
getPrefix(): stringReturns the cache key prefix
isEnabled(?string $module = null): boolWhether caching is enabled globally or for a module
usesTags(): boolWhether the driver supports cache tags
getTtl(string $type, ?string $module = null): intReturns TTL in seconds for the given type

Key Generation ​

MethodSignatureDescription
generateCacheKey(string $module, string $routeName, string $type, array $params = []): stringBuilds a fully-qualified cache key
generateRecordKey(string $module, string $routeName, $id): stringBuilds a key for a single model record
getModuleTags(string $module): arrayTags for an entire module
getRouteTags(string $module, string $routeName): arrayTags for a specific module route
getTypeTags(string $module, string $routeName, string $type): arrayTags for a type within a route
generateRelationTag(string $modelClass, $id): stringTag for a single model instance
generateRelationTags(array $relations): arrayTags for multiple model instances

Read / Write ​

MethodSignatureDescription
remember(string $key, int $ttl, Closure $callback, ...): mixedCache or compute a value with TTL
rememberForever(string $key, Closure $callback, ...): mixedCache a value without expiry
rememberWithRelations(string $key, int $ttl, Closure $callback, ..., array $relations): mixedCache with relation tags
get(string $key, $default = null, ...): mixedRetrieve a cached value
put(string $key, $value, int $ttl, ...): boolStore a value with TTL
putWithRelations(string $key, $value, int $ttl, ..., array $relations): boolStore with relation tags
has(string $key, ...): boolCheck if a key exists
forget(string $key, ...): boolDelete a specific key
flush(): boolFlush all Modularous cache entries

Invalidation ​

MethodSignatureDescription
invalidateModule(string $module): boolInvalidate all cache for a module
invalidateModuleRoute(string $module, string $routeName): boolInvalidate all cache for a route
invalidateByRelatedModel(string $modelClass, $id): boolInvalidate by a single related model
invalidateByRelatedModels(array $relations): intInvalidate by multiple related models
invalidateByPattern(string $pattern): intInvalidate by key pattern
invalidateForModel(Model $model): voidInvalidate all cache entries for a model instance
invalidateCountCaches(string $module, string $routeName): voidInvalidate count caches for a route
invalidateIndexCaches(string $module, string $routeName): voidInvalidate index caches for a route

Stats ​

MethodSignatureDescription
getStats(?string $module = null): arrayReturns cache statistics

Usage ​

php
use Unusualify\Modularous\Facades\ModularousCache;

$items = ModularousCache::remember(
    ModularousCache::generateCacheKey('Blog', 'posts', 'index'),
    ModularousCache::getTtl('index', 'Blog'),
    fn() => $repository->getIndexItems(),
    'Blog',
    'posts'
);

// Invalidate after a save
ModularousCache::invalidateModuleRoute('Blog', 'posts');