tianshupei / taggable-repository-cache
There is no license information available for the latest version (dev-master) of this package.
This package's canonical repository appears to be gone and the package has been frozen as a result.
dev-master
2017-04-28 14:33 UTC
This package is auto-updated.
Last update: 2019-03-14 19:08:32 UTC
README
在使用Laravel 5 Repositories过程中发现每个Repository下的find
,paginate
等的缓存分组是通过文件来存贮这些cache key,所以想通过Redis或Memcached这类缓存的 标签缓存 来分组各个Repository的缓存key.
怎么使用?
composer require tianshupei/taggable-repository-cache
首先 App\Providers\AppServiceProvider
中重新绑定缓存修改监听器,如下:
$this->app->bind(
\Prettus\Repository\Listeners\CleanCacheRepository::class,
\Tsp\TaggedCacheRepository\CleanCacheRepository::class
);
Repository
中添加CacheableInterface
接口和TaggableRepositoryCacheTrait
trait, 如下:
<?php
namespace App\Repositories;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\UserRepository;
use App\Entities\User;
use App\Validators\UserValidator;
use Prettus\Repository\Traits\CacheableRepository;
use Tsp\TaggedCacheRepository\TaggedCacheRepositoryTrait;
/**
* Class UserRepositoryEloquent
* @package namespace App\Repositories;
*/
class UserRepositoryEloquent extends BaseRepository implements UserRepository, CacheableInterface
{
use TaggableRepositoryCacheTrait;
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return User::class;
}
/**
* Specify Validator class name
*
* @return mixed
*/
public function validator()
{
return UserValidator::class;
}
/**
* Boot up the repository, pushing criteria
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
}