|
|
<?php |
|
|
|
|
|
namespace Kanboard\Decorator; |
|
|
|
|
|
use Kanboard\Core\Cache\CacheInterface; |
|
|
use Kanboard\Model\UserModel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserCacheDecorator |
|
|
{ |
|
|
protected $cachePrefix = 'user_model:'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $cache; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $userModel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(CacheInterface $cache, UserModel $userModel) |
|
|
{ |
|
|
$this->cache = $cache; |
|
|
$this->userModel = $userModel; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getByUsername($username) |
|
|
{ |
|
|
$key = $this->cachePrefix.$username; |
|
|
$user = $this->cache->get($key); |
|
|
|
|
|
if ($user === null) { |
|
|
$user = $this->userModel->getByUsername($username); |
|
|
$this->cache->set($key, $user); |
|
|
} |
|
|
|
|
|
return $user; |
|
|
} |
|
|
} |
|
|
|