Per-Module Setup ​
Enable module-route cache for a single Modularous module in four steps: config, entity readiness, repository/controller readiness, and graph rebuild.
Checklist ​
| Step | Action | Verify |
|---|---|---|
| 1 | Add cache.modules.{Module} block to app config | ModularousCache::isEnabled('Module', 'Route', 'counts') returns true |
| 2 | Confirm entity extends Modularous Model (includes HasCaching) | CacheObserver fires on save |
| 3 | Confirm repository uses CacheableTrait (generated by default) | Counts and index respect shouldUseCache |
| 4 | Rebuild graph + optional warm | php artisan modularous:cache:graph rebuild |
| 5 | Add dependencies if cross-module invalidation needed | Edit related model, confirm dependent route cache clears |
Step 1 — Configuration ​
Add to config/modularous.php or config/modularity.php:
'cache' => [
'modules' => [
'BusinessPackage' => [
'enabled' => true,
'ttl' => [
'counts' => 900,
'formattedItem' => 1800,
'formItem' => 900,
],
'routes' => [
'Package' => [
'enabled' => true,
'types' => [
'counts' => true,
'index' => false,
'record' => false,
'formattedItem' => true,
'formItem' => true,
'presentationItem' => false,
],
],
],
],
],
],For public CMS pilot routes, enable presentationItem separately (see CMS Public Pages):
'PrimaryPage' => [
'routes' => [
'Home' => [
'types' => [
'presentationItem' => true,
],
'ttl' => [
'presentationItem' => 900,
],
],
],
],Start with one pilot route before enabling index on large tables.
See Configuration for TTL hierarchy and env overrides.
Step 2 — Entity and HasCaching ​
Unusualify\Modularous\Entities\Model already includes HasCaching. Any entity that extends it gets cache invalidation automatically — do not re-declare the trait on standard module entities.
<?php
namespace Modules\BusinessPackage\Entities;
use Unusualify\Modularous\Entities\Model;
class Package extends Model
{
// Optional: declare manual dependents
// public function getCacheDependents(): array { ... }
}Inherited HasCaching behavior:
- Uses
Cacheablefor module/route name resolution - Boots
CacheObserverviabootHasCaching() - Exposes
shouldCacheInvalidate(),withoutCacheInvalidation(),preventDependentWarming()
Only override or opt out when needed — e.g. a model that does not extend Modularous Model, or an entity that must skip invalidation for specific saves. Cross-module dependencies still apply to any model whose changes should clear dependent route caches.
Step 3 — Repository and Controller ​
Repository ​
Module repositories generated by Modularous include CacheableTrait, which provides:
cacheableCount()for filter badgesgetPaginator()→ cached index whenindextype enabledgetByIdCached()for single recordstrackCacheRelations(default true) for relation tags
Opt out per request:
$repository->withoutCache()->getPaginator(...);
$repository->withoutRelationTracking()->getByIdCached($id);Controller ​
BaseController descendants use CacheableResponse for:
getFormItem()→formItemcachegetFormattedIndexItem()→formattedItemcache
No extra wiring required if the module follows standard Modularous scaffolding.
Step 4 — Graph and Warm ​
php artisan modularous:cache:graph rebuild
php artisan modularous:cache:warm BusinessPackage Package --counts --formattedItems
php artisan modularous:cache:stats BusinessPackageStep 5 — Cross-Module Dependencies ​
When route A displays data from model B (e.g. press release list shows company name), add B to dependencies or ensure B's entity defines getEloquentRelationships() so the graph links them.
Copy patterns from b2press-app/config/modularity.php cache.dependencies block.
User-Aware Repositories ​
If the repository uses CreatorTrait or AssignmentTrait:
- Keep
user_aware: true(default) - Do not expect global count warmup to work — counts are per-user
- Test with multiple admin accounts to confirm isolated cache keys
Disabling Cache Temporarily ​
// Single repository chain
$repo->withoutCache()->getById($id);
// Single model save without invalidation storm
$model->withoutCacheInvalidation()->update($attrs);
// Global — .env
MODULAROUS_RESOURCE_CACHE_ENABLED=falsePilot Recommendation (b2press-cms) ​
For admin panel pilot (Faz 4 in the CMS performance plan):
BusinessPackage+PrimaryPagemodules first- Enable
counts,formattedItem,formItemonly - Keep
indexandrecordoff until query patterns are stable - Schedule
modularous:cache:graph rebuildweekly and warm after content imports
Public CMS pages remain separate — see CMS Public Pages.
See Also ​
- Cache Types — choose which
typesto enable - Invalidation — observer and dependency behavior
- Warmup — post-setup warm commands