spatie/laravel-partialcache
最新稳定版本:1.3.0
Composer 安装命令:
composer require spatie/laravel-partialcache
包简介
Blade directive to cache rendered partials in laravel
README 文档
README
???? THIS PACKAGE HAS BEEN ABANDONED ????
We don't use this package anymore in our own projects and cannot justify the time needed to maintain it anymore. That's why we have chosen to abandon it. Feel free to fork our code and maintain your own copy.
Laravel Cache Partial Blade Directive
This package provides a Blade directive for Laravel >=5.1 to cache rendered partials in Laravel.
Install
You can install the package via Composer:
$ composer require spatie/laravel-partialcache
In Laravel 5.5 the package's service provider and facade will be registered automatically. In older versions of Laravel, you must register them manually:
// config/app.php 'providers' => [ ... Spatie\PartialCache\PartialCacheServiceProvider::class, ], 'aliases' => [ ... 'PartialCache' => Spatie\PartialCache\PartialCacheFacade::class, ],
The facade is optional, but the rest of this guide assumes you're using it.
Optionally publish the config files:
$ php artisan vendor:publish --provider="Spatie\PartialCache\PartialCacheServiceProvider" 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, a key unique to the rendered view, and a cache tag for the rendered view. If no minutes are provided, the view will be remembered until you manually remove it from the cache.
Note that this caches the rendered html, not the rendered php like blade's default view caching.
{{-- 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) {{-- With an added key (cache entry will be partialcache.user.profile.{$user->id}) --}} @cache('user.profile', null, null, $user->id) {{-- With an added tag (only supported by memcached and others) }} @cache('user.profile', null, null, $user->id, 'userprofiles') {{-- With array of tags (only supported by memcached and others) }} @cache('user.profile', null, null, $user->id, ['user', 'profile', 'location']) Clearing The PartialCache
You can forget a partialcache entry with PartialCache::forget($view, $key).
PartialCache::forget('user.profile', $user->id); If you have used @cache on an entry along with tags and your cache driver supports them (like memcached and other), you need to use the same tags to forget the entry.
// With an added tag PartialCache::forget('user.profile', $user->id, 'userprofiles'); // With array of tags PartialCache::forget('user.profile', $user->id, ['user', 'profile', 'location']);
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 three options specified in the config file:
partialcache.enabled: Fully enable or disable the cache. Defaults totrue.partialcache.directive: The name of the blade directive to register. Defaults tocache.partialcache.key: The base key that used for cache entries. Defaults topartialcache.partialcache.default_duration: The default cache duration in minutes, setnullto remember forever. Defaults tonull.
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
Support us
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
License
The MIT License (MIT). Please see License File for more information.
spatie/laravel-partialcache 适用场景与选型建议
spatie/laravel-partialcache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 234.14k 次下载、GitHub Stars 达 203, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「view」 「partial」 「spatie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/laravel-partialcache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/laravel-partialcache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/laravel-partialcache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Non-standard PHP library (NSPL) - functional primitives toolbox and more
Shoot aims to make providing data to your templates more manageable
A collection of functions to make working with the standard php library a little easier for function composition. Allows the creation of partially applied library functions, to work as close to pure fucntions as possible.
repository php library
Illuminate View for Morningmedley.
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 234.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 208
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04