An open API service indexing awesome lists of open source software.

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.

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 }}