Configuration
The published config file lives at config/millicache.php in your Acorn application. It controls the StoreResponse middleware and automatic cache clearing for Artisan commands — all other caching settings (TTL, grace period, exclusions, compression, etc.) are managed by MilliCache itself.
Config Reference#Copied!
1return [
2
3 'middleware' => [
4 'enabled' => true,
5 'groups' => ['web'],
6 ],
7
8 'clear' => [
9 'optimize:clear' => 'route*',
10 'route:clear' => 'route*',
11 'route:cache' => 'route*',
12 ],
13
14];
| Key | Type | Default | Description |
|---|---|---|---|
middleware.enabled |
bool |
true |
Whether to auto-register the StoreResponse middleware |
middleware.groups |
list<string> |
['web'] |
Router middleware groups the middleware is appended to |
clear |
array<string, string> |
(see above) | Maps Artisan commands to flag patterns for automatic cache clearing |
Adding Middleware Groups#Copied!
By default, the middleware is only added to the web group. If you have Acorn routes in other middleware groups that should be cached, add them to the groups array:
1'middleware' => [
2 'enabled' => true,
3 'groups' => ['web', 'api'],
4],
The middleware is appended to each group via pushMiddlewareToGroup(), so it runs after all other middleware in the group — exactly when the response is ready to be captured.
Disabling Automatic Registration#Copied!
If you need full control over where the middleware runs, disable auto-registration and register it manually:
1// config/millicache.php
2'middleware' => [
3 'enabled' => false,
4 'groups' => ['web'],
5],
Then register the middleware yourself in a service provider or route file:
1use MilliCacheAcornHttpMiddlewareStoreResponse;
2
3// In a route group
4Route::middleware([StoreResponse::class])->group(function () {
5 Route::get('/cached-route', [MyController::class, 'index']);
6});
7
8// Or append to a group manually
9$router->pushMiddlewareToGroup('web', StoreResponse::class);
Automatic Cache Clearing#Copied!
The clear config maps Artisan commands to MilliCache flag patterns. When a listed command runs, all cache entries matching its flag pattern are automatically cleared.
1'clear' => [
2 'optimize:clear' => 'route*',
3 'route:clear' => 'route*',
4 'route:cache' => 'route*',
5],
The key is the Artisan command name, the value is the flag pattern to clear:
| Pattern | Clears |
|---|---|
route* |
All Acorn route caches (named and unnamed) |
route:products:index |
Only the products.index route cache |
route:api* |
All API route caches |
* |
All MilliCache entries (including WordPress page caches) |
You can add your own commands to the list:
1'clear' => [
2 'optimize:clear' => 'route*',
3 'route:clear' => 'route*',
4 'route:cache' => 'route*',
5 'deploy:finish' => 'route*', // custom deployment command
6],
To disable automatic clearing entirely, set clear to an empty array:
1'clear' => [],
Related Configuration#Copied!
All other caching behavior is configured through MilliCache and MilliRules:
- TTL, grace period, compression — MilliCache Configuration
- Cache exclusions, conditions, rules — MilliRules Documentation
- Route-aware conditions — Acorn MilliRules Documentation