Skip to content

Commit e150f28

Browse files
committed
Fixes #62
1 parent 63f180d commit e150f28

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/CacheKey.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function make(
3131
$key .= $this->getOffsetClause();
3232
$key .= $this->getLimitClause();
3333
$key .= $keyDifferentiator;
34+
dump($key);
3435
$key = sha1($key);
3536

3637
return $key;
@@ -90,9 +91,11 @@ protected function getQueryColumns(array $columns) : string
9091

9192
protected function getTypeClause($where) : string
9293
{
93-
return in_array($where['type'], ['In', 'Null', 'NotNull'])
94+
$type =in_array($where['type'], ['In', 'Null', 'NotNull'])
9495
? strtolower($where['type'])
95-
: '';
96+
: strtolower($where['operator']);
97+
98+
return str_replace(' ', '_', $type);
9699
}
97100

98101
protected function getValuesClause(array $where = null) : string
@@ -149,8 +152,8 @@ protected function getOtherClauses(array $where, string $carry = null) : string
149152
return '';
150153
}
151154

152-
$value = array_get($where, 'value');
153-
$value .= $this->getTypeClause($where);
155+
$value = $this->getTypeClause($where);
156+
$value .= "_" . array_get($where, 'value');
154157
$value .= $this->getValuesClause($where);
155158

156159
return "{$carry}-{$where['column']}_{$value}";

tests/Unit/CachedBuilderTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,42 @@ public function testDelete()
693693
$this->assertNull($cachedResult);
694694
$this->assertNull($deletedAuthor);
695695
}
696+
697+
private function processWhereClauseTestWithOperator(string $operator)
698+
{
699+
$author = (new Author)->first();
700+
$authors = (new Author)
701+
->where('name', $operator, $author->name)
702+
->get();
703+
$keyParts = [
704+
'genealabslaravelmodelcachingtestsfixturesauthor-name',
705+
'_',
706+
str_replace(' ', '_', strtolower($operator)),
707+
'_',
708+
$author->name,
709+
];
710+
$key = sha1(implode('', $keyParts));
711+
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
712+
713+
$cachedResults = cache()
714+
->tags($tags)
715+
->get($key);
716+
$liveResults = (new UncachedAuthor)
717+
->where('name', $operator, $author->name)
718+
->get();
719+
720+
$this->assertEmpty($authors->diffAssoc($cachedResults));
721+
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
722+
}
723+
724+
public function testWhereClauseParsingOfOperators()
725+
{
726+
$this->processWhereClauseTestWithOperator('=');
727+
$this->processWhereClauseTestWithOperator('!=');
728+
$this->processWhereClauseTestWithOperator('<>');
729+
$this->processWhereClauseTestWithOperator('>');
730+
$this->processWhereClauseTestWithOperator('<');
731+
$this->processWhereClauseTestWithOperator('LIKE');
732+
$this->processWhereClauseTestWithOperator('NOT LIKE');
733+
}
696734
}

0 commit comments

Comments
 (0)