Skip to content

Commit a81fec6

Browse files
committed
WIP
1 parent c7d0c7f commit a81fec6

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/CacheKey.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,26 @@ protected function getValuesClause(array $where = null) : string
114114
return "";
115115
}
116116

117-
$values = is_array(array_get($where, "values"))
117+
$values = $this->getValuesFromWhere($where);
118+
$values = $this->getValuesFromBindings($values);
119+
120+
return "_" . $values;
121+
}
122+
123+
protected function getValuesFromWhere(array $where) : string
124+
{
125+
return is_array(array_get($where, "values"))
118126
? implode("_", $where["values"])
119127
: "";
128+
}
120129

130+
protected function getValuesFromBindings(string $values) : string
131+
{
121132
if (! $values && $this->query->bindings["where"] ?? false) {
122133
$values = implode("_", $this->query->bindings["where"]);
123134
}
124135

125-
return "_" . $values;
136+
return $values;
126137
}
127138

128139
protected function getWhereClauses(array $wheres = []) : string

src/Traits/Cachable.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function flushCache(array $tags = [])
5656

5757
$this->cache($tags)->flush();
5858

59-
[$cacheCooldown, $invalidatedAt, $savedAt] = $this->getModelCacheCooldown($this);
59+
[$cacheCooldown] = $this->getModelCacheCooldown($this);
6060

6161
if ($cacheCooldown) {
6262
$cachePrefix = "genealabs:laravel-model-caching:"
@@ -73,6 +73,14 @@ public function flushCache(array $tags = [])
7373
}
7474
}
7575

76+
protected function getCachePrefix() : string
77+
{
78+
return "genealabs:laravel-model-caching:"
79+
. (config('laravel-model-caching.cache-prefix')
80+
? config('laravel-model-caching.cache-prefix', '') . ":"
81+
: "");
82+
}
83+
7684
protected function makeCacheKey(
7785
array $columns = ['*'],
7886
$idColumn = null,
@@ -96,10 +104,7 @@ protected function makeCacheTags() : array
96104

97105
protected function getModelCacheCooldown(Model $instance)
98106
{
99-
$cachePrefix = "genealabs:laravel-model-caching:"
100-
. (config('laravel-model-caching.cache-prefix')
101-
? config('laravel-model-caching.cache-prefix', '') . ":"
102-
: "");
107+
$cachePrefix = $this->getCachePrefix();
103108
$modelClassName = get_class($instance);
104109

105110
$cacheCooldown = $instance
@@ -135,10 +140,7 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)
135140
return;
136141
}
137142

138-
$cachePrefix = "genealabs:laravel-model-caching:"
139-
. (config('laravel-model-caching.cache-prefix')
140-
? config('laravel-model-caching.cache-prefix', '') . ":"
141-
: "");
143+
$cachePrefix = $this->getCachePrefix();
142144
$modelClassName = get_class($instance);
143145

144146
$instance

0 commit comments

Comments
 (0)