Skip to content

Commit bda4eaa

Browse files
committed
Add QueryCacheModule::appendCacheTags and Builder::selectSub
1 parent 460fd39 commit bda4eaa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Query/Builder.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,22 @@ public function useWritePdo()
3333

3434
return $this;
3535
}
36+
37+
/**
38+
* Add a subselect expression to the query.
39+
*
40+
* @param \Closure|$this|string $query
41+
* @param string $as
42+
* @return $this
43+
*
44+
* @throws \InvalidArgumentException
45+
*/
46+
public function selectSub($query, $as)
47+
{
48+
if(get_class($query) == self::class) {
49+
$this->appendCacheTags($query->getCacheTags() ?? []);
50+
}
51+
52+
return parent::selectSub($query, $as);
53+
}
3654
}

src/Traits/QueryCacheModule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ public function cacheTags(array $cacheTags = [])
272272
return $this;
273273
}
274274

275+
/**
276+
* Append tags to the cache.
277+
*
278+
* @param array $cacheTags
279+
* @return \Rennokki\QueryCache\Query\Builder
280+
*/
281+
public function appendCacheTags(array $cacheTags = [])
282+
{
283+
$this->cacheTags = array_unique(array_merge($this->cacheTags ?? [], $cacheTags));
284+
285+
return $this;
286+
}
287+
275288
/**
276289
* Use a specific cache driver.
277290
*

0 commit comments

Comments
 (0)