valeryq/cacheable

Laravel Cacheable

v1.1.0 2015-11-16 13:25 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:31:50 UTC


README

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

需求

  • PHP >= 5.5.9
  • Laravel >= 5.1

安装

使用Composer安装此包

composer require valeryq/cacheable

用法

您必须在您的类中实现Cacheable接口,并且可以使用CacheableTrait来实现接口中的方法。

例如(针对仓库)

<?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);
        });
    }

    ....
}

许可证

Laravel Cacheable是开源软件,根据MIT许可证授权。