Skip to content

valeryq/cacheable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Cacheable

Build Status Scrutinizer Scrutinizer Code Quality Total Downloads Latest Stable Version License

Requirements

  • PHP >= 5.5.9
  • Laravel >= 5.1

Installation

Require this package with composer:

composer require valeryq/cacheable

Usage

You must implements the Cacheable contract into your class and you can use the CacheableTrait instead realized methods from contract.

For example (for repositories):

<?php namespace App\Repositories\Cacheable;

use App\Models\Product;
use Valeryq\Cacheable\Contracts\Cacheable;
use Valeryq\Cacheable\Traits\CacheableTrait;

class CacheableProductRepository implements Cacheable
{
    use CacheableTrait;

    /**
     * Find product by id
     *
     * @param $id
     *
     * @return Product
     * @throws ModelNotFoundException
     */
    public function find($id)
    {
        return $this->cache()->remember('your_key', 60, function() {
            return Product::findOrFail($id);
        });
    }

    ....
}

License

The Laravel Cacheable is open-sourced software licensed under the MIT license