承接 swiss-devjoy/blade-staticcache-directive 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

swiss-devjoy/blade-staticcache-directive

最新稳定版本:v1.1.0

Composer 安装命令:

composer require swiss-devjoy/blade-staticcache-directive

包简介

Put chunks of your Blade template into immutable static cache files

README 文档

README

Latest Version on Packagist Total Downloads

Increase performance by putting chunks of your Blade template into immutable static cache files. This package provides a directive for Blade templates that allows you to easily create static cache files for specific sections of your views. With OPCache enabled, this can significantly reduce the time it takes to render your views, especially for large and complex templates.

Installation

You can install the package via composer:

composer require swiss-devjoy/blade-staticcache-directive

You can publish the config file with:

php artisan vendor:publish --tag="blade-staticcache-directive-config"

This is the contents of the published config file:

return [
    'enabled' => env('BLADE_STATICCACHE_DIRECTIVE_ENABLED', true),
    'strip_whitespace_between_tags' => env('BLADE_STATICCACHE_DIRECTIVE_STRIP_WHITESPACE_BETWEEN_TAGS', true),

    // Cache profile which generates the unique key for the cache entry
    'cache_profile' => \SwissDevjoy\BladeStaticcacheDirective\CacheProfile::class,
];

Usage

This is a blade template.

@staticcache('my-cache-key')
    {{ $this->aVeryExpensiveMethod() }}
@endstaticcache

To clear the cache you can run the following command:

$ php artisan blade-staticcache:clear

To include some additional stats in your response about cached/uncached blade chunks, you can use the provided middleware:

For laravel 11.x and newer:

Add the middleware definition to the bootstrap app.

// bootstrap/app.php


->withMiddleware(function (Middleware $middleware) {
    ...
    $middleware->web(append: [
        ...
        \SwissDevjoy\BladeStaticcacheDirective\BladeStaticcacheStatsMiddleware::class,
    ]);
})

For laravel 10.x and earlier:

Add the middleware definition to the http kernel.

// app/Http/Kernel.php

...

protected $middlewareGroups = [
   'web' => [
       ...
       \SwissDevjoy\BladeStaticcacheDirective\BladeStaticcacheStatsMiddleware::class,
   ],

Cache Profile

The cache profile is responsible for generating the unique key for the cache entry. By default, it uses the \SwissDevjoy\BladeStaticcacheDirective\CacheProfile class, which generates a key based on the cache key parameter passed to the @staticcache directive AND the current locale.

Inspiration

The main idea came from a tweet (https://x.com/dgurock/status/1577314908982706176) and the following package: https://github.com/ryangjchandler/blade-cache-directive

I did some basic benchmarks with a huge template and a lot of data.

Using Ryan's package and redis as a cache driver, I got 85 req/s. Using Ryan's package and file as a cache driver, I got 99 req/s. Using my package, I got 110 req/s.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固