Cache Management
Unfold CMS ships with two independent caching layers that work together to serve pages fast.
Two Layers
1. Page Cache (HTML cache)
Writes the rendered HTML of each public page to public/cache/*.html. On a cache hit, a tiny PHP script (public/cache-server.php) serves the file before Laravel boots — no database query, no PHP framework overhead. Typical hit time: 5–10ms.
Cached HTML is automatically invalidated when you save a post, change a menu, or update site settings.
Page caching is enabled by default. Toggle it at Settings > Cache > Enable Page Cache.
Requirements:
public/cache/directory must exist and be writable by the web server user (e.g.www-data)- Works on Apache, Nginx, Caddy, LiteSpeed — no webserver config needed
Bypassed for:
- Authenticated users (cookie
unfold_authpresent) - POST/PUT/DELETE requests
- Requests with a query string
- Admin panel and API routes
2. Settings / Application Cache
Caches database settings and other frequently read data in memory (L1) and in a persistent backend (L2). Prevents redundant queries on every request.
L1 — Request memory: Active for the current request only. Always on, no config needed.
L2 — Persistent: Survives across requests. Configured via Settings > Cache > Cache Driver.
| Driver | Good for |
|---|---|
file (default) |
Any hosting environment |
redis |
High-traffic VPS — fastest |
database |
When the file system is restricted |
Admin Panel
Navigate to Tools > Cache to:
- See the current driver and page-cache status
- Clear individual caches or all caches at once
Clearing Caches
| Cache | What it clears |
|---|---|
| Application Cache | Cached settings and data |
| Page Cache | All cached HTML files in public/cache/ |
| View Cache | Compiled Blade templates |
| Route Cache | Cached route list |
| Config Cache | Cached .env + config values |
| All | Everything above |
Clear caches after:
- Changing
.envvalues (requires Config cache clear) - Modifying template or config files
- Updating the CMS
- Troubleshooting stale content
Production Optimization
php artisan config:cache # cache configuration
php artisan route:cache # cache routes
php artisan view:cache # cache Blade views
After caching config, .env changes require re-running config:cache.
Troubleshooting
Pages not caching (always slow):
- Check
public/cache/exists:ls -la public/cache/ - Check it's writable by the web server:
ls -la public/ | grep cache - If missing:
mkdir public/cache && chown www-data:www-data public/cache && chmod 775 public/cache - Confirm toggle is on: Settings > Cache > Enable Page Cache
Stale content showing:
- Clear all caches from Tools > Cache
- Or run
php artisan cache:page:flush
CSRF / 419 errors on cached pages:
- This is handled automatically. Each cached page runs a tiny JS snippet that refreshes the CSRF token before any form is submitted.
Artisan Commands
php artisan cache:page:flush # delete all cached HTML files
php artisan cache:page:flush --url=/blog # delete one URL
php artisan cache:page:stats # show files, size, oldest, newest
php artisan cache:page:prune --older-than=604800 # remove files older than N seconds
Related
- Page Cache Internals — developer deep-dive
- Configuration — all settings reference
- Shared Hosting — cache considerations for shared hosting