Need help with laravel-partialcache?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

204 Stars 24 Forks MIT License 58 Commits 0 Opened issues


Blade directive to cache rendered partials in laravel

Services available


Need anything else?

Contributors list


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

Latest Version on Packagist Software License Quality Score StyleCI Total Downloads

This package provides a Blade directive for Laravel >=5.1 to cache rendered partials in Laravel.


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"


The package registers a blade directive,

. The cache directive accepts the same arguments as
, 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 --}}

{{-- 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('', 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

(note: this is only supported by drivers that support tags), or clear your entire cache.


Configuration isn't necessary, but there are three options specified in the config file:

  • partialcache.enabled
    : Fully enable or disable the cache. Defaults to
  • partialcache.directive
    : The name of the blade directive to register. Defaults to
  • partialcache.key
    : The base key that used for cache entries. Defaults to
  • partialcache.default_duration
    : The default cache duration in minutes, set
    to remember forever. Defaults to

Change log

Please see CHANGELOG for more information what has changed recently.


Please see CONTRIBUTING for details.


If you discover any security related issues, please email [email protected] instead of using the issue tracker.


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.


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.


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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.