achillesp / matryoshka
Laravel的俄罗斯套娃缓存。
0.2.1
2017-10-31 22:19 UTC
Requires
- php: ^7.0
- illuminate/config: ^5.5
- illuminate/support: ^5.5
Requires (Dev)
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^6.3
This package is auto-updated.
Last update: 2024-09-25 20:42:53 UTC
README
Matryoshka 是一个为 Laravel 提供视图俄罗斯套娃缓存的包。此包基于一系列 laracasts 课程并稍作修改 查看 Laracasts.com。
安装
步骤 1:Composer
从命令行运行
composer require achillesp/matryoshka
步骤 2:服务提供者(Laravel < 5.5)
对于您的 Laravel 应用,打开 config/app.php
并在 providers
数组中追加
Achillesp\Matryoshka\MatryoshkaServiceProvider::class
配置
此包使用一个配置文件,您可以通过发布到您的配置目录来覆盖它。
php artisan vendor publish --provider=MatryoshkaServiceProvider --tag=config
在配置文件中,您可以设置缓存使用的标签。如果您无法使用支持标签的缓存,请将其设置为 null。
此外,在配置文件中,您还可以设置是否希望在本地机器上清除缓存以帮助开发。
使用方法
要使用此插件,您可以在视图中使用 @cache
和 @endcache
blade 指令。指令需要一个标识符,可以是唯一的字符串、模型或集合。
缓存 HTML
@cache('my-cache-key') <div> <h1>Hello World</h1> </div> @endcache
缓存模型
@cache($post) <article> <h2>{{ $post->title }}></h2> <p>Written By: {{ $post->author->username }}</p> <div class="body">{{ $post->body }}</div> </article> @endcache
为了缓存一个模型,需要额外的步骤。您需要在模型中使用 Cacheable 特性。
use Achillesp\Matryoshka\Cacheable; class Post extends Eloquent { use Cacheable; }
缓存集合
@cache($posts) @foreach ($posts as $post) @include ('post') @endforeach @endcache
许可
MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。