Skip to content

Commit

Permalink
fixed disable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Franek authored and Tobias Franek committed Jun 9, 2017
1 parent 24a96ab commit 2fd03e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function findBy(array $params, array $sort = [], $limit = null) {
*/
public function findAll(array $sort = [], $limit = null) {
$data = ExecutionHandler::execute($this, []);

if (!empty($sort)) {
$field = array_keys($sort)[0];
$sortingOrder = $sort[$field];
Expand Down Expand Up @@ -287,6 +286,8 @@ protected static function initMemcached() {
$memcached = new \Memcached();
$memcached->addServer($host, $port);
$cacheDriver->setMemcached($memcached);
} else {
return false;
}
self::$cache = $cacheDriver;
return self::$cache;
Expand Down
6 changes: 2 additions & 4 deletions src/Util/ExecutionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ private function __construct() {
* @param Repository $repository
* @param array $params
* @return AbstractModel[]
* @internal param string $model
* @internal param Webuntis $instance
*/
public static function execute(Repository $repository, array $params) {
$model = $repository->getModel();
$interfaces = class_implements($model);
$cacheDriver = $repository::getCache();
if ($cacheDriver->contains($model::METHOD) && isset($interfaces[CachableModelInterface::class])) {
if ($cacheDriver && $cacheDriver->contains($model::METHOD) && isset($interfaces[CachableModelInterface::class])) {
$data = $cacheDriver->fetch($model::METHOD);
} else {
$result = $repository->getInstance()->getClient()->execute($model::METHOD, $params);
$data = $repository->parse($result);

if (isset($interfaces[CachableModelInterface::class])) {
if ($cacheDriver && isset($interfaces[CachableModelInterface::class])) {
if ($model::CACHE_LIFE_TIME) {
$cacheDriver->save($model::METHOD, $data, $model::CACHE_LIFE_TIME);
} else {
Expand Down
16 changes: 9 additions & 7 deletions src/Webuntis.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(array $config) {

$cache = Repository::getCache();
$generalConfig = WebuntisFactory::getConfig();
if($cache->contains($config['username']) && (!isset($generalConfig['only_admin']) || $generalConfig['only_admin'] == false)) {
if ($cache && $cache->contains($config['username']) && (!isset($generalConfig['only_admin']) || $generalConfig['only_admin'] == false)) {
$data = $cache->fetch($config['username']);
$this->currentUserId = -1;
if(isset($data['userId'])){
Expand Down Expand Up @@ -121,12 +121,14 @@ public function authenticate($username, $password) {
$this->currentUserType = $result['personType'];

$cache = Repository::getCache();
$cache->save($username, [
'session' => $result['sessionId'],
'userId' => $this->currentUserId,
'userType' => $this->currentUserType,
'tokenCreatedAt' => new \DateTime()
], 86400);
if ($cache) {
$cache->save($username, [
'session' => $result['sessionId'],
'userId' => $this->currentUserId,
'userType' => $this->currentUserType,
'tokenCreatedAt' => new \DateTime()
], 86400);
}

$this->session = $result['sessionId'];

Expand Down

0 comments on commit 2fd03e7

Please sign in to comment.