Skip to content

Commit c7ad020

Browse files
committed
Fixes #93
1 parent e672859 commit c7ad020

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/CachedBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function avg($column)
2323
return $this->cachedValue(func_get_args(), $cacheKey);
2424
}
2525

26-
public function count($columns = ["*"])
26+
public function count($columns = "*")
2727
{
2828
if (! $this->isCachable()) {
2929
return parent::count($columns);
3030
}
3131

32-
$cacheKey = $this->makeCacheKey($columns, null, "-count");
32+
$cacheKey = $this->makeCacheKey([$columns], null, "-count");
3333

3434
return $this->cachedValue(func_get_args(), $cacheKey);
3535
}

tests/Integration/CachedBuilderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,28 @@ public function testCountModelResultsCreatesCache()
243243
$this->assertEquals($liveResults, $cachedResults);
244244
}
245245

246+
public function testCountWithStringCreatesCache()
247+
{
248+
$authors = (new Author)
249+
->with('books', 'profile')
250+
->count("id");
251+
$key = sha1('genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesauthor_id-books-profile-count');
252+
$tags = [
253+
'genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesauthor',
254+
'genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesbook',
255+
'genealabs:laravel-model-caching:testing:genealabslaravelmodelcachingtestsfixturesprofile',
256+
];
257+
258+
$cachedResults = $this->cache()->tags($tags)
259+
->get($key)['value'];
260+
$liveResults = (new UncachedAuthor)
261+
->with('books', 'profile')
262+
->count("id");
263+
264+
$this->assertEquals($authors, $cachedResults);
265+
$this->assertEquals($liveResults, $cachedResults);
266+
}
267+
246268
public function testFindModelResultsCreatesCache()
247269
{
248270
$author = collect()->push((new Author)->find(1));

0 commit comments

Comments
 (0)