Skip to content

Commit 7336836

Browse files
committed
WIP - caching select clauses properly
1 parent 4dc52ff commit 7336836

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/CacheKey.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ protected function getOrderByClauses() : string
9898

9999
protected function getQueryColumns(array $columns) : string
100100
{
101-
if ($columns === ["*"] || $columns === []) {
101+
if (($columns === ["*"]
102+
|| $columns === [])
103+
&& ! $this->query->columns
104+
) {
102105
return "";
103106
}
104107

108+
if ($this->query->columns) {
109+
return "_" . implode("_", $this->query->columns);
110+
}
111+
105112
return "_" . implode("_", $columns);
106113
}
107114

tests/Integration/CachedBuilder/SelectTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,29 @@ public function testSelectWithRawColumns()
4949
$this->assertEquals($liveResults, $books);
5050
$this->assertEquals($liveResults, $cachedResults);
5151
}
52+
53+
// public function testSelectFieldsAreCached()
54+
// {
55+
// $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first');
56+
// $tags = [
57+
// 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor',
58+
// ];
59+
60+
// $authorFields = (new Author)
61+
// ->select("id", "name")
62+
// ->first()
63+
// ->getAttributes();
64+
// $uncachedFields = (new UncachedAuthor)
65+
// ->select("id", "name")
66+
// ->first()
67+
// ->getAttributes();
68+
// $cachedFields = $this
69+
// ->cache()
70+
// ->tags($tags)
71+
// ->get($key)['value']
72+
// ->getAttributes();
73+
74+
// $this->assertEquals($cachedFields, $authorFields);
75+
// $this->assertEquals($cachedFields, $uncachedFields);
76+
// }
5277
}

0 commit comments

Comments
 (0)