Skip to content

Commit

Permalink
Fixes cache decorator issue
Browse files Browse the repository at this point in the history
  • Loading branch information
richan-fongdasen committed Aug 19, 2020
1 parent 3179e2c commit 410efc3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/CacheableDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ private function generateCustomTags(Collection $tags, Model $object)
$class = class_basename(get_class($object));
$baseTags = (array) $this->repository->cacheTags();

$tags->push($class.':'.$object->getKey());
$tags->push($class . ':' . $object->getKey());

foreach ($baseTags as $tag) {
$tags->push($tag.':'.$class.':'.$object->getKey());
$tags->push($tag . ':' . $class . ':' . $object->getKey());
}
}

Expand All @@ -76,6 +76,17 @@ private function generateTags($args)
return $tags->sort()->unique()->all();
}

/**
* Get the correct return value if the repository returns itself
*
* @param mixed $value
* @return mixed
*/
private function getReturnValue($value)
{
return ($value === $this->repository) ? $this : $value;
}

/**
* Determine if the given object is a custom tag instance.
*
Expand Down Expand Up @@ -122,10 +133,10 @@ public function __call($method, $args)
}

if (!$this->methodIsCacheable($method)) {
return call_user_func_array([$repository, $method], $args);
return $this->getReturnValue(call_user_func_array([$repository, $method], $args));
}

return $this->service->retrieve(
return $this->getReturnValue($this->service->retrieve(
$this->generateTags($args),
$repository->cacheKey($method, $args),
$repository->cacheDuration(),
Expand All @@ -134,6 +145,6 @@ function () use ($repository, $method, $args) {

return ($result !== null) ? $result : false;
}
);
));
}
}

0 comments on commit 410efc3

Please sign in to comment.