temperworks / laravel-russian-doll-cache
Laravel Russian Doll Cache Blade 指令
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-09-11 21:12:44 UTC
README
简介
本软件包提供了一种Blade指令,用于在Laravel中缓存渲染的局部视图,基于memcached(默认)或redis的LRU自动淘汰策略(可选)。
在此实现中,您不需要显式设置缓存键。缓存键将根据传递给局部视图的数据自动生成。
如果数据实现了getCacheKey
(通过包含Cacheable特质),则键基于对象类、id和updated_at时间戳。当对象更改时,键会更新,视图将在下次访问时重新生成。
如果数据没有实现getCacheKey
,则使用MD5散列作为缓存键。
当存储空间满时,缓存存储将负责自动淘汰使用最少的键。
安装
请确保您的缓存存储已配置max_memory
并且设置了适当的淘汰策略。
您可以通过Composer安装此包
$ composer require temperworks/laravel-russian-doll-cache
首先注册包的服务提供者和外观
// config/app.php 'providers' => [ ... TemperWorks\RussianDollCache\RussianDollCacheServiceProvider::class, ],
用法
该软件包注册了一个Blade指令@cache
。缓存指令接受与@include
相同的参数,还可以为视图缓存时间提供可选参数(分钟数)。如果没有提供分钟数,视图将一直保留,直到被缓存存储删除。
只有显式传递给局部视图的数据将在其中可用。与@include
的行为不同,全局变量将被忽略以确保所有变量都将表示在缓存键中。
{{-- 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)
清除局部视图缓存
由于我们依赖于缓存存储自动刷新旧数据,因此不需要手动删除键。
如果您想刷新所有条目,您需要调用PartialCache::flush()
(注意:这仅适用于支持标签的驱动程序),或者清除您的整个缓存。
配置
配置不是必需的,但配置文件中指定了一些选项
russian-doll-cache.enabled
:完全启用或禁用缓存。默认为true
。russian-doll-cache.directive
:要注册的Blade指令的名称。默认为cache
。russian-doll-cache.key
:用于缓存条目的基本键。默认为partialcache
。
鸣谢
本软件包是由出色的网页设计公司Spatie从spatie-partialcache分叉的。
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。