Skip to content

Commit 8c1ec1c

Browse files
committed
WIP
1 parent 1f51b40 commit 8c1ec1c

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/Traits/Cachable.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@ public function cache(array $tags = [])
2222
}
2323

2424
if (is_subclass_of($cache->getStore(), TaggableStore::class)) {
25-
$tags = $this->addTagsWhenCalledFromCachedBuilder($tags);
2625
$cache = $cache->tags($tags);
2726
}
2827

2928
return $cache;
3029
}
3130

32-
protected function addTagsWhenCalledFromCachedBuilder(array $tags) : array
33-
{
34-
$usesCachableTrait = collect(class_uses($this))
35-
->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable");
36-
37-
return $tags;
38-
}
39-
4031
public function disableCache()
4132
{
4233
$this->isCachable = false;
@@ -99,30 +90,38 @@ protected function getModelCacheCooldown(Model $instance)
9990
{
10091
$cachePrefix = $this->getCachePrefix();
10192
$modelClassName = get_class($instance);
102-
103-
$cacheCooldown = $instance
104-
->cache()
105-
->get("{$cachePrefix}:{$modelClassName}-cooldown:seconds");
93+
[$cacheCooldown, $invalidatedAt, $savedAt] = $this
94+
->getCacheCooldownDetails($instance, $cachePrefix, $modelClassName);
10695

10796
if (! $cacheCooldown) {
10897
return [null, null, null];
10998
}
11099

111-
$invalidatedAt = $instance
112-
->cache()
113-
->get("{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at");
114-
115-
$savedAt = $instance
116-
->cache()
117-
->get("{$cachePrefix}:{$modelClassName}-cooldown:saved-at");
118-
119100
return [
120101
$cacheCooldown,
121102
$invalidatedAt,
122103
$savedAt,
123104
];
124105
}
125106

107+
protected function getCacheCooldownDetails(
108+
Model $instance,
109+
string $cachePrefix,
110+
string $modelClassName
111+
) : array {
112+
return [
113+
$instance
114+
->cache()
115+
->get("{$cachePrefix}:{$modelClassName}-cooldown:seconds"),
116+
$instance
117+
->cache()
118+
->get("{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"),
119+
$instance
120+
->cache()
121+
->get("{$cachePrefix}:{$modelClassName}-cooldown:saved-at"),
122+
];
123+
}
124+
126125
protected function checkCooldownAndRemoveIfExpired(Model $instance)
127126
{
128127
[$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance);

0 commit comments

Comments
 (0)