https://github.com/alpshq/statamic-cache-evader
A statamic Addon to help you evade the static cache and support forms on cached pages.
https://github.com/alpshq/statamic-cache-evader
statamic-addon
Last synced: 3 months ago
JSON representation
A statamic Addon to help you evade the static cache and support forms on cached pages.
- Host: GitHub
- URL: https://github.com/alpshq/statamic-cache-evader
- Owner: alpshq
- License: mit
- Created: 2022-02-18T01:01:59.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-21T16:43:14.000Z (over 2 years ago)
- Last Synced: 2025-06-14T13:53:29.529Z (9 months ago)
- Topics: statamic-addon
- Language: PHP
- Homepage:
- Size: 153 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Cache Evader
> Cache evasion for Statamic 3
This Addon provides various simple ways to serve **uncached content** on **cached pages** and makes it possible to use Statamic forms on cached pages.
## What you can do
- [Serve whole uncached pages based on an HTTP GET parameter](https://github.com/alpshq/statamic-cache-evader#usage-cache-evading-based-on-http-get-parameter)
- [Use Statamic forms on cached pages](https://github.com/alpshq/statamic-cache-evader#usage-forms)
- **NEW**: [Inject uncached partials as part of cached pages](https://github.com/alpshq/statamic-cache-evader#usage-inject-uncached-partials-as-part-of-cached-pages)
## Support
If you like the Addon consider [following me on Twitter](https://twitter.com/jakub_jo). If you've feature requests, feel free to start a discussion by opening a GitHub issue. If you've any further questions or want to discuss an opportunity with me, drop me a line at [hello@jakub.io](mailto:hello@jakub.io).
## Installation
You can install the addon using composer:
```
composer require alpshq/statamic-cache-evader
```
Alternatively you can install the addon by navigating to [Statamic's marketplace](https://statamic.com/addons/alps/cache-evader) within your Control Panel and searching there for `Cache Evader`.
## Usage: Cache evading based on HTTP GET parameter
Essentially any URL to which you add the GET parameter `_nc` with *any* value will evade the cache.
### Modifier
To add the corresponding HTTP parameter name to any URL you can use the built-in modifier [evade_cache](src/Modifiers/EvadeCache.php):
```html
Link to current (uncached) URL
```
#### How does the cache evading work?
- The Addon will replace Statamic's default Cache middleware with the Addon's [StaticCache](src/Http/Middleware/StaticCache.php) middleware.
- The replaced middleware will check if a cache evading parameter is part of the request. If a parameter is found, the cache is evaded. If not, Statamic default behavior applies.
## Usage: Forms
To make your forms work in cached environments make sure to add the [{{ cache_evader_scripts }}](src/Tags/CacheEvaderScripts.php) tag right before the closing `
{{ template_content }}
...
{{ cache_evader_scripts }}
{{ template_content }}
...
{{ cache_evader_scripts }}