From ddeb89e2c6622f197d1b7738042182b34d5054ed Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 17 Dec 2016 13:39:03 -0500 Subject: Add cache decorator for UserModel --- app/Decorator/UserCacheDecorator.php | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/Decorator/UserCacheDecorator.php (limited to 'app/Decorator') diff --git a/app/Decorator/UserCacheDecorator.php b/app/Decorator/UserCacheDecorator.php new file mode 100644 index 00000000..1cfe31c9 --- /dev/null +++ b/app/Decorator/UserCacheDecorator.php @@ -0,0 +1,59 @@ +cache = $cache; + $this->userModel = $userModel; + } + + /** + * Get a specific user by the username + * + * @access public + * @param string $username Username + * @return array + */ + 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; + } +} -- cgit v1.2.3