PHP code example of spatie / laravel-partialcache

1. Go to this page and download the library: Download spatie/laravel-partialcache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / laravel-partialcache example snippets


// config/app.php

'providers' => [
  ...
  Spatie\PartialCache\PartialCacheServiceProvider::class,
],

'aliases' => [
  ...
  'PartialCache' => Spatie\PartialCache\PartialCacheFacade::class,
],

PartialCache::forget('user.profile', $user->id);

// With an added tag
PartialCache::forget('user.profile', $user->id, 'userprofiles');

// With array of tags
PartialCache::forget('user.profile', $user->id, ['user', 'profile', 'location']);
bash
$ php artisan vendor:publish --provider="Spatie\PartialCache\PartialCacheServiceProvider"

{{-- 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'])