tv2regionerne / statamic-cache
Requires
- php: ^8.2
- pixelfear/composer-dist-plugin: ^0.1.5
- statamic/cms: ^4.0 || ^5.0
Requires (Dev)
- laravel/pint: ^1.13
- mockery/mockery: ^1.3.1
- nunomaduro/collision: ^6.0 || ^7.0
- orchestra/testbench: ^7.0 || ^8.0
- pestphp/pest: ^2.24
- phpunit/phpunit: ^9.0 || ^10.0
- dev-main
- dev-feature/lock-when-flushing
- dev-feature/cache-headers
- dev-split-brain-check-configurable
- dev-syda-update
- dev-fix/some-issues-with-cache-clearing
- dev-invalidate-when-no-db-entry
- dev-fix/actually-invalidate-the-cache
- dev-fix/chunk-when-we-have-a-config-limit
- dev-fix/autocache-urls
- dev-feature/test-suite-merge-models
- dev-feature/unique-job-on-queue
- dev-feature/nuke-cache-if-we-dont-have-a-tracker
- dev-feature/custom_cache_driver
- dev-feature/chunked
- dev-feature/queued
- dev-fix/use-hooks-properly
- dev-fix/switch-to-simpler-cache-approach
- dev-feature/move-to-middleware
- dev-feature/add-expiry-and-tags
- dev-feature/syda
- dev-feature/refactor-to-use-hooks
This package is auto-updated.
Last update: 2024-11-04 10:47:19 UTC
README
Statamic Autocache is an addon that automatically caches the content of any partials for a faster response time and selective invalidation
How to Install
Run the following command from your project root:
composer require tv2regionerne/statamic-cache
Then run the migrations:
php artisan migrate
You can also optionally publish the config:
php artisan vendor:publish --tag=statamic-cache-config
How to Use
The addon should work automatically in most cases. It adds hooks to partial, nav and collection tags, as well as augmentation of entries and globals to determine what content is included in what partials. This data is then added to a database store that is used to determine what cached data should be invalidated at what times.
The default cache is used, or you can specify a cache store called statamic_autocache
if you want to have more control over when it is cleared.
Middleware
The autocache middleware will automatically be added to your web
middleware stack. If you want to include it to other stacks simply add:
\Tv2regionerne\StatamicCache\Http\Middleware\Autocache::class
Store
The addon comes with a Facade for interacting with the Store:
\Tv2regionerne\StatamicCache\Facades\Store
If you want to add extra data to the store you can do so using in your AppServiceProvider, eg:
MyTag::hook('init', function () { Store::mergeTags(['my_tag:id']); });
Make sure you also invalidate the tag in a listener:
Store::invalidateContent(['my_tag:id']);
Custom cache driver with database index
Run the migrations to add the static_cache table.
This add-on will automatically add a redis_with_database
cache driver to your Statamic install. To use it change the half measure static cache driver in config/statamic/static_caching.php
to use redis_with_database
, and ensure statamic.static_caching.strategy
is set to half
.
'half' => [ 'driver' => 'redis_with_database', 'expiry' => null, ],