2017 © Pedro Peláez
 

library query-cache

Easily Cache Eloquent Collections

image

kyrenator/query-cache

Easily Cache Eloquent Collections

  • Monday, October 26, 2015
  • by Hootlex
  • Repository
  • 1 Watchers
  • 6 Stars
  • 203 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

IMPORTANT NOTICE: This package is not maintained and maybe not working at all. Use it at your own risk!!, (*1)

Laravel 5 query cache

This Laravel 5 package allows you to easily cache eloquent queries by implementing laravel 4 remember method., (*2)

How to use

Step 1: Install Through Composer

composer require kyrenator/query-cache

Step 2: Use QueryCache In Your Model

<?php namespace App;

use Kyrenator\QueryCache\QueryCache;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {
    use QueryCache;
}

Step 3: Use remember Method When Quering Eloquent

When calling remember method you can tell it for how many minutes you want the query be cached. If you dont specify the minutes, the query will be cached for 60 minutes., (*3)

\App\Post::remember()->take(3)->get();

//use cache tags
\App\Post::remember()->cacheTags('posts', 'fresh')->take(3)->get();

More Features

Global Cache

If you want you can cache all queries for a specific model by siply defining cacheAll var inside your model. QueryCache will aply remember method to all model queries., (*4)

<?php namespace App;

use Kyrenator\QueryCache\QueryCache;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {
    use QueryCache;
    protected $cacheAll = true;
}

Clear Cache On Change

If you want the cache to be flushed when you create, delete, or update an existing model then define $clearOnChange, (*5)

<?php namespace App;

use Kyrenator\QueryCache\QueryCache;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {
    use QueryCache;
    protected $clearOnChange = true;
}

Cache Tags

QueryCache will use the model name as cache tags. You can also define custon cache tags., (*6)

<?php namespace App;

use Kyrenator\QueryCache\QueryCache;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {
    use QueryCache;
    protected $clearOnChange = true;
    protected $cacheTags = 'fresh';
    protected $cacheAll = true;
}

The Versions

26/10 2015

dev-master

9999999-dev

Easily Cache Eloquent Collections

  Sources   Download

MIT

The Requires

 

by kyrenator

27/04 2015

v0.0.1

0.0.1.0

Easily Cache Eloquent Collections

  Sources   Download

MIT

The Requires

 

by kyrenator

27/04 2015

v0.0.2

0.0.2.0

Easily Cache Eloquent Collections

  Sources   Download

MIT

The Requires

 

by kyrenator

28/03 2015

v1.0.1

1.0.1.0

Easily Cache Eloquent Collections

  Sources   Download

MIT

The Requires

 

by kyrenator

27/03 2015

v1.0

1.0.0.0

Easily Cache Eloquent Collections

  Sources   Download

MIT

The Requires

 

by kyrenator