1. Go to this page and download the library: Download ulex/cached-repositories library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Repository created successfully.
Interface created successfully.
Decorator created successfully.
Add Model in `models` array in config/cached-repositories.php
# Example when injecting to a controller
public function __construct(UserRepositoryInterface $userRepository)
{
$this->userRepository = $userRepository;
}
...
public function get($name)
{
//retrieve from db and then cache the result
$user = $this->userRepository->getBy('name', $userName);
//retrieve straight from db, don't cache
$user = $this->userRepository->fromDb()->getBy('name', $userName);
}
public function getUserInfo($user_id)
{
return $this->remember(__FUNCTION__, func_get_args());
}
public function flushGetKeys($model, $attributes = null)
{
$user_id = $model->user_id;
$key = $this->key('getUserInfo', compact('user_id'));
parent::flushGetKeys($model, $attributes);
}
public function getUserInfo($user_id)
{
return $this->model->query()
->where('user_id', '=', $user_id)
->whereNotNull('something')->get();
}