temperworks / laravel-russian-doll-cache
Laravel Russian Doll Cache Blade Directive
Installs: 95 616
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.0
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- dev-master
- 0.1
- dev-bridge-webbased-jobbpage
- dev-bridgefix
- dev-bugfix-dashboard-alerts-without-photo
- dev-bugfix-finqle
- dev-bugfix-invoices-not-paid
- dev-bugfix-invoicing
- dev-bugfix-linked-invoicegroups
- dev-bugfix-memory-exhaused-bug
- dev-bugfix-paymentbatch-sync
- dev-bugfix_unsub_from_emails
- dev-cleanup-jobsearch-settingds
- dev-compliance-remove-autoaccept
- dev-cost-center
- dev-disable-factoring-temperfees
- dev-enforce_ini_settings_on_new_machine
- dev-factoring-contract
- dev-factoring_fee_update
- dev-fix-bridge-succespage
- dev-fix-ib47
- dev-ib47-to-menu
- dev-ignore-AuthorizationException
- dev-logged-in-to-dashboard
- dev-new-vat-percentage
- dev-no-footer-on-bridge
- dev-optimizely-wrapper
- dev-registration-flow-for-apps
- dev-request-magic-link-after-bridged-signup
- dev-reupload-invoice-to-finqle
- dev-simplify_invoicing
- dev-simplify_invoicing_v2
- dev-test_wkhtmltopdf
- dev-upload-ubl-to-finqle
This package is not auto-updated.
Last update: 2024-12-18 22:16:58 UTC
README
Intro
This package provides a Blade directive to cache rendered partials in Laravel, based on the LRU auto evict policy of memcached (by default) or redis (optional)
In this implementation you don't need to explicitly set cache keys. The cache key will be automatically generated based on the data you pass to the partial.
If the data implements getCacheKey
(by including the Cacheable trait) the key is based on the class, id and updated_at timestamp of the object. When the object changes, the key updates and the view will be regenerated on the next visit.
If the data does not implement getCacheKey
, an md5 hash is used as cache key.
The cache store will be responsible for auto evicting the less recently used keys when the store is full.
Install
Make sure your cache store has max_memory
configured and a proper eviction policy is set.
You can install the package via Composer:
$ composer require temperworks/laravel-russian-doll-cache
Start by registering the package's service provider and facade:
// config/app.php 'providers' => [ ... TemperWorks\RussianDollCache\RussianDollCacheServiceProvider::class, ],
Usage
The package registers a blade directive, @cache
. The cache directive accepts the same arguments as @include
, plus optional parameters for the amount of minutes a view should be cached for. If no minutes are provided, the view will be remembered untill it gets deleted by the cache store.
Only the data you pass explicitly to the partial will be available within. Unlike the behavior of @include
, global variables will be ignored to make sure all the variables will be represented in the cache key.
{{-- Simple example --}}
@cache('footer.section.partial')
{{-- With extra view data --}}
@cache('products.card', ['product' => $category->products->first()])
{{-- For a certain time --}}
{{-- (cache will invalidate in 60 minutes in this example, set null to remember forever) --}}
@cache('homepage.news', null, 60)
Clearing The PartialCache
Since we rely on the cache store to automatically flush old data, it's not needed to manually remove keys.
If you want to flush all entries, you'll need to either call PartialCache::flush()
(note: this is only supported by drivers that support tags), or clear your entire cache.
Configuration
Configuration isn't necessary, but there are some options specified in the config file:
russian-doll-cache.enabled
: Fully enable or disable the cache. Defaults totrue
.russian-doll-cache.directive
: The name of the blade directive to register. Defaults tocache
.russian-doll-cache.key
: The base key that used for cache entries. Defaults topartialcache
.
Credits
This package is forked from on spatie-partialcache by the awesome webdesign agency Spatie.
License
The MIT License (MIT). Please see License File for more information.