rodrigopedra / russian-doll-caching
Laravel Russian Doll Caching
Installs: 83
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/rodrigopedra/russian-doll-caching
Requires
- illuminate/contracts: ~5.3|~5.4|~5.5|~5.6
- illuminate/support: ~5.3|~5.4|~5.5|~5.6
README
Efficient view caching.
Inspired by the excellent series at https://laracasts.com/series/russian-doll-caching-in-laravel .
Watch that series to understand the concepts around it and to use it properly, for example: how to invalidate the cache upwards.
Installation
In your terminal/shell run:
composer require rodrigopedra/russian-doll-caching
If you're using Laravel 5.3 or 5.4 you need to register the service provider in
your config/app.php providers array:
// ... 'providers' => [ // ... RodrigoPedra\RussianDollCaching\RussianDollCachingServiceProvider::class, ], // ...
Configuration
In your terminal/shell run:
php artisan vendor:publish --provider="RodrigoPedra\RussianDollCaching\RussianDollCachingServiceProvider"
You can configure a should_cache constraint, so you can skip caching, for example, while developing locally.
Usage
Use the @russian directive in your blade templates the same way you would use the @include directive.
You can optionally inform a custom prefix that will be prepended to the cache key.
@russian('path.to.view', compact('user', 'articles'), 'version-prefix') @russian('path.to.other.view', compact('user', 'articles')) {{-- caution here, the cache key will only be the view name hash! --}} @russian('path.to.another.view')
You can also pass multiple prefixes as an array, that will be prepended to the cache item's key:
@russian('path.to.other.view', compact('user'), [ 'v1', 'home' ])
If your cache mechanism supports tagging, like memcached or redis, all cache items will be
cached with a russian tag.
Key calculation
The caching mechanism will try to use the first element in the data array as part of the cache key.
You should use the RussianCacheableModel trait in your models or use the RussianCacheableCollection in
your custom collections. This traits add a getCacheKey method to this objects so you can
FAQ
-
Why are my views not updating?
Try running
php artisan view:clearandphp artisan cache:clear. Also, while developing, set theshould_cacheconfig key tofalse. -
Can I flush just the items cached by this package?
If you use a caching mechanism that supports tagging (
memcachedorredis) all the cached items are created with arussiantag. So you can clear only these items running\Cache::tags('russian')->flush()inphp artisan tinker
License
This package is open-sourced software licensed under the MIT license.