Cache chunks of your Blade markup with ease. 🔪

Overview

Blade Cache Directive

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Cache chunks of your Blade markup with ease.

Installation

You can install the package via Composer:

composer require ryangjchandler/blade-cache-directive

You can publish the config file with:

php artisan vendor:publish --provider="RyanChandler\BladeCacheDirective\BladeCacheDirectiveServiceProvider" --tag="blade-cache-directive-config"

This is the contents of the published config file:

return [

    'ttl' => 3_600,

];

Usage

This package adds a new @cache Blade directive. It accepts 2 arguments - the cache key and a TTL.

@cache('current_time', 30)
    {{ now() }}
@endcache

When used inside of a Blade template, the content between the 2 directives will be cached using Laravel's application cache. If a TTL (in seconds) isn't provided, the default TTL of 1 hour will be used instead.

If you want to cache the content for a particular model, i.e. a User model, you can use string interpolation to change the key.

@cache("user_profile_{$user->id}")
    {{ $user->name }}
@endcache

When a new user is passed to this view, a separate cache entry will be created.

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.

You might also like...
A package to easily make use of SVG icons in your Laravel Blade views.
A package to easily make use of SVG icons in your Laravel Blade views.

Blade Icons A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan. Turn... !-- camera.svg --

Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.
Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.

Laravel Blade Sortable Demo Repo Installation You can install the package via composer: composer require asantibanez/laravel-blade-sortable After the

A package to easily make use of Iconsax in your Laravel Blade views.
A package to easily make use of Iconsax in your Laravel Blade views.

Blade Iconsax A package to easily make use of Iconsax in your Laravel Blade views. This package contains 1.000 icons in 6 diferent styles, a total of

Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Storybook for Laravel Blade 🚀

Blast — Storybook for Laravel Blade 🚀 What is Blast? Blast is a low maintenance component library using Storybook Server, built to integrate into you

Useful blade components and functionality for most Laravel projects.

laravel-base Note: Package is still in early stages of development, so functionality is subject to change. LaravelBase is a package I've created to pr

Create Laravel views (blade template) using 'php artisan' command-line interface
Create Laravel views (blade template) using 'php artisan' command-line interface

About LaraBit Have you ever wonder to create Laravel views (Blade Templates) using the same type of artisan commands that you usually use to create ne

An opinionated blade template formatter for Laravel that respects readability
An opinionated blade template formatter for Laravel that respects readability

blade-formatter An opinionated blade template formatter for Laravel that respects readability Online Demo Features Automatically Indents markup inside

Releases(v0.3.1)
  • v0.3.1(May 31, 2022)

    What's Changed

    • Add env variable to config by @applyACS in https://github.com/ryangjchandler/blade-cache-directive/pull/5

    New Contributors

    • @applyACS made their first contribution in https://github.com/ryangjchandler/blade-cache-directive/pull/5

    Full Changelog: https://github.com/ryangjchandler/blade-cache-directive/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Mar 9, 2022)

    What's Changed

    • Add tests for cache directive by @yvesdaxmaz in https://github.com/ryangjchandler/blade-cache-directive/pull/1
    • Add support for Laravel 9 by @phpfour in https://github.com/ryangjchandler/blade-cache-directive/pull/3

    New Contributors

    • @yvesdaxmaz made their first contribution in https://github.com/ryangjchandler/blade-cache-directive/pull/1
    • @phpfour made their first contribution in https://github.com/ryangjchandler/blade-cache-directive/pull/3

    Full Changelog: https://github.com/ryangjchandler/blade-cache-directive/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(May 22, 2021)

  • v0.1.0(May 22, 2021)

Owner
Ryan Chandler
Ryan Chandler
Create inline partials in your Blade templates with ease

Create inline partials in your Blade templates with ease. This package introduces a new @capture directive that allows you to capture small parts of y

Ryan Chandler 27 Dec 8, 2022
Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

Blade UI Kit 1.2k Jan 5, 2023
Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline.

Blade Snip Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline: <div class="products"> @snip('pr

Jack Sleight 18 Dec 4, 2022
Use Kafka Producers and Consumers in your laravel app with ease!

Laravel Kafka Do you use Kafka in your laravel packages? All packages I've seen until today, including some built by myself, does not provide a nice s

Mateus Junges 325 Jan 5, 2023
Cast your Eloquent model attributes to Value Objects with ease.

Laravel Value Objects Cast your Eloquent model attributes to value objects with ease! Requirements This package requires PHP >= 5.4. Using the latest

Red Crystal Code 23 Dec 30, 2022
Laravel-model-mapper - Map your model attributes to class properties with ease.

Laravel Model-Property Mapper This package provides functionality to map your model attributes to local class properties with the same names. The pack

Michael Rubel 15 Oct 29, 2022
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

Malik Alleyne-Jones 17 Aug 25, 2022
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

UB Labs 12 Jan 17, 2022
Cagilo - a set of simple components for use in your views Laravel Blade.

Cagilo - a set of simple components for use in your views Laravel Blade. Official Documentation Documentation for Cagilo can be found on its we

Cagilo 151 Dec 6, 2022
A Laravel Code Generator based on your Models using Blade Template Engine

Laravel Code Generator is a PHP Laravel Package that uses Blade template engine to generate code for you. The difference between other code generators

Victor Yoalli 59 Dec 5, 2022