https://github.com/handmadeweb/statamic-multi-cacher
Statamic Multi Cacher is a caching strategy that allows you to specify multiple caching strategies.
https://github.com/handmadeweb/statamic-multi-cacher
Last synced: about 1 year ago
JSON representation
Statamic Multi Cacher is a caching strategy that allows you to specify multiple caching strategies.
- Host: GitHub
- URL: https://github.com/handmadeweb/statamic-multi-cacher
- Owner: HandmadeWeb
- License: mit
- Created: 2021-07-25T01:03:33.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-27T22:02:08.000Z (over 4 years ago)
- Last Synced: 2025-03-24T12:44:27.427Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 62.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/handmadeweb/statamic-multi-cacher)
[](https://packagist.org/packages/handmadeweb/statamic-multi-cacher)
[](LICENSE.md)
[](https://github.com/handmadeweb/statamic-multi-cacher/actions/workflows/tests.yml)

Statamic Multi Cacher is a caching strategy "redirector" of sorts, it can be used to provide different caching strategies based on your own logic.
An example of this could be to bypass/disable the cache for super admins and serve the `half` strategy to everyone else.
## THIS IS A BETA
Please be aware that it is not recommended to use this in production just yet.
## Requirements
* Statamic 3.1 or higher
## Installation
You can install the package via composer:
```bash
composer require handmadeweb/statamic-multi-cacher
```
## Usage
First add the strategy to your `static_cache` config
```php
'strategies' => [
'half' => [
'driver' => 'application',
'expiry' => null,
],
'full' => [
'driver' => 'file',
'path' => public_path('static'),
'lock_hold_length' => 0,
],
'multi' => [
'driver' => 'multi-cacher',
],
],
```
Then specify the name of the strategies that you want to be available to the `multi-cacher`
```php
'multi' => [
'driver' => 'multi-cacher',
'strategies' => [
'half',
'full',
],
],
```
Then update the `static_cache` strategy at the top of the configuration to:
```php
'strategy' => 'multi',
```
It is important to note, that if strategies are omitted or are empty, then the `multi-cacher` strategy will default to `null`.
The `null` strategy will always be available for selection, so you don't need to add it to your strategies section.
If you don't override the `CacheSelector` which is `\HandmadeWeb\StatamicMultiCacher\CacheSelector` then the first strategy will always be used, In the above example this would be `half`.
Overriding can be done by extending the `CacheSelector` class like so:
```php
isSuper()){
return $this->multiCacher()->cachers()->get('null');
}
// Cache everyone else with the half strategy.
return $this->multiCacher()->cachers()->get('half');
}
}
```
And then updating your `static_cache` configuration to be as follows:
```php
'multi' => [
'driver' => 'multi-cacher',
'selector' => \App\Cachers\MyMultiCacher::class,
'strategies' => [
'half',
],
],
```
## Changelog
Please see [CHANGELOG](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/CONTRIBUTING.md) for details.
## Credits
- [Handmade Web & Design](https://github.com/handmadeweb)
- [Michael Rook](https://github.com/michaelr0)
- [All Contributors](https://github.com/handmadeweb/statamic-multi-cacher/graphs/contributors)
## License
The MIT License (MIT). Please see [License File](https://github.com/handmadeweb/statamic-multi-cacher/blob/main/LICENSE.md) for more information.