2017 © Pedro Peláez
 

library laravel-fragment-caching

Fragment Caching support helper

image

gchaincl/laravel-fragment-caching

Fragment Caching support helper

  • Tuesday, March 8, 2016
  • by gchaincl
  • Repository
  • 3 Watchers
  • 33 Stars
  • 1,285 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Not supported No Maintenance Intended

This project is not supported anymore, you can try matryoshka instead., (*1)

laravel-fragment-caching

Add a Fragment caching support helper. Blog post, (*2)

Installation

Run: composer require gchaincl/laravel-fragment-caching:dev-master or * add: "require": { "gchaincl/laravel-fragment-caching": "dev-master" },to composer.json * run: composer install * add: The following to your app/config/app.php, (*3)

$providers => array(
  ...
    'Gchaincl\LaravelFragmentCaching\ViewServiceProvider',
)

Usage

In your view:, (*4)



    @foreach ($posts as $post) @cache("post" . $post->id)
  • {{ link_to_route('post.show', $post->title, $post->id) }} ({{ $post->user->username }})
  • @endcache @endforeach

First time we load that view, Framework will run 3 queries:, (*5)

select * from "posts"
select * from "users" where "users"."id" = '5' limit 1
select * from "users" where "users"."id" = '5' limit 1

Second time, as fragments are already cached, there will be just one query:, (*6)

select * from "posts"

Conditional caching

In situations where you don't always want to cache a block you can use @cacheif($condition, $cacheId), (*7)

{{-- Only use the cache for guests, admins will always get content rendered from the template --}}
@cacheif( Auth::guest(), "post" . $post->id)
    <li> {{ link_to_route('post.show', $post->title, $post->id) }} (@if (Auth::guest()) {{ $post->user->username }} @else {{ $post->user->email }} @endif)</li>
@endcacheif

Tip

To update view rendering on model changes, you should expire your fragments:, (*8)

// app/model/Post.php

class Post extends Eloquent {

    public static function boot() {
        parent::boot();
        static::updated(function($model) {
            Cache::forget("post" . $model->id);
        });
    }
}

The Versions

08/03 2016

dev-master

9999999-dev

Fragment Caching support helper

  Sources   Download

MIT

The Requires

 

by Gustaf Shin

laravel cache helper fragment

11/05 2014

v0.0.1

0.0.1.0

Fragment Caching support helper

  Sources   Download

MIT

The Requires

 

by Gustaf Shin

laravel cache helper fragment

29/04 2014

dev-blade_extension

dev-blade_extension

Fragment Caching support helper

  Sources   Download

MIT

The Requires

 

by Gustaf Shin

laravel cache helper fragment