Download the PHP package slydeath/laravel-nested-caching without Composer
On this page you can find all versions of the php package slydeath/laravel-nested-caching. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download slydeath/laravel-nested-caching
More information about slydeath/laravel-nested-caching
Files in slydeath/laravel-nested-caching
Package laravel-nested-caching
Short Description Nested Caching for Laravel with caches stack
License MIT
Informations about the package laravel-nested-caching
Nested Caching for Laravel with caches stack
Minimum requirements
- PHP 7.4
- Laravel 8
Installation
Add package to composer.json:
Open config/app.php
and add the service provider to the array providers
:
To place the configuration file, run:
How to use?
Caching any HTML chunk
To cache any HTML chunk, you just need to pass the caching key to the @cache
directive fragment:
Model caching
To enable model caching support, add the trait to it NestedCacheable
:
In the template, to cache a model, you need to pass its instance to the @cache
directive:
Caching the model for a specified time
To cache the model for a certain time, specify the lifetime in minutes as the second parameter:
Updating the «parent»
For update the cache of the «parent model», we need setup touches:
Usage example:
resources/views/user.blade.php
resources/views/user-car.blade.php
Collection caching
Example of caching a collection:
How to remove stack cache?
Just run this code at bottom of your page:
Workflow with another caches
How to collect keys?
Keys are automatically collected in SlyDeath\NestedCaching\CacheWrittenListener
if another-caching
is enabled,
but you must save them manually (at the end of executing app) if you want to use them elsewhere:
How to clear the stack of another caches?
Just callclearAnotherCaches
method:
How to save keys for different pages?
You can generate dynamically the cache key (for example from the page id):
How to clear the stack of another caches with custom cache key?
Just callclearAnotherCaches
method and provide the key:
Enable PhpStorm support
Go to the Settings → PHP → Blade
, then uncheck Use default settings. Go to Directives tab and press «+» to add
another one custom directive:
- Name:
cache
- Checkbox Has parameters →
true
- Prefix:
- Suffix:
And add close directive without parameters:
- Name:
endcache
orendCache
, whatever you use