diff --git a/src/CacheKey.php b/src/CacheKey.php index 7acd7cb..92cf460 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -19,8 +19,8 @@ class CacheKey public function __construct( array $eagerLoad, - Model $model, - Builder $query + $model, + $query ) { $this->eagerLoad = $eagerLoad; $this->model = $model; @@ -54,7 +54,9 @@ protected function getIdColumn(string $idColumn) : string protected function getLimitClause() : string { - if (! $this->query->limit) { + if (! property_exists($this->query, "limit") + || ! $this->query->limit + ) { return ""; } @@ -74,7 +76,9 @@ protected function getModelSlug() : string protected function getOffsetClause() : string { - if (! $this->query->offset) { + if (! property_exists($this->query, "offset") + || ! $this->query->offset + ) { return ""; } @@ -83,6 +87,12 @@ protected function getOffsetClause() : string protected function getOrderByClauses() : string { + if (! property_exists($this->query, "orders") + || ! $this->query->orders + ) { + return ""; + } + $orders = collect($this->query->orders); return $orders @@ -100,12 +110,15 @@ protected function getQueryColumns(array $columns) : string { if (($columns === ["*"] || $columns === []) - && ! $this->query->columns + && (! property_exists($this->query, "columns") + || ! $this->query->columns) ) { return ""; } - if ($this->query->columns) { + if (property_exists($this->query, "columns") + && $this->query->columns + ) { return "_" . implode("_", $this->query->columns); } @@ -302,7 +315,9 @@ protected function getWheres(array $wheres) : Collection { $wheres = collect($wheres); - if ($wheres->isEmpty()) { + if ($wheres->isEmpty() + && property_exists($this->query, "wheres") + ) { $wheres = collect($this->query->wheres); } diff --git a/src/CacheTags.php b/src/CacheTags.php index e911ddd..715bb58 100644 --- a/src/CacheTags.php +++ b/src/CacheTags.php @@ -16,8 +16,8 @@ class CacheTags public function __construct( array $eagerLoad, - Model $model, - Builder $query + $model, + $query ) { $this->eagerLoad = $eagerLoad; $this->model = $model; diff --git a/src/CachedBelongsToMany.php b/src/CachedBelongsToMany.php new file mode 100644 index 0000000..0350194 --- /dev/null +++ b/src/CachedBelongsToMany.php @@ -0,0 +1,15 @@ +isCachable()) { - return parent::avg($column); - } - - $cacheKey = $this->makeCacheKey(["*"], null, "-avg_{$column}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function count($columns = "*") - { - if (! $this->isCachable()) { - return parent::count($columns); - } - - $cacheKey = $this->makeCacheKey([$columns], null, "-count"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function decrement($column, $amount = 1, array $extra = []) - { - $this->cache($this->makeCacheTags()) - ->flush(); - - return parent::decrement($column, $amount, $extra); - } - - public function delete() - { - $this->cache($this->makeCacheTags()) - ->flush(); - - return parent::delete(); - } - - /** - * @SuppressWarnings(PHPMD.ShortVariable) - */ - public function find($id, $columns = ["*"]) - { - if (! $this->isCachable()) { - return parent::find($id, $columns); - } - - $idKey = collect($id) - ->implode('_'); - $preStr = is_array($id) - ? 'find_list' - : 'find'; - $cacheKey = $this->makeCacheKey($columns, null, "-{$preStr}_{$idKey}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function first($columns = ["*"]) - { - if (! $this->isCachable()) { - return parent::first($columns); - } - - if (! is_array($columns)) { - $columns = [$columns]; - } - - $cacheKey = $this->makeCacheKey($columns, null, "-first"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function forceDelete() - { - $this->cache($this->makeCacheTags()) - ->flush(); - - return parent::forceDelete(); - } - - public function get($columns = ["*"]) - { - if (! $this->isCachable()) { - return parent::get($columns); - } - - $cacheKey = $this->makeCacheKey($columns); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function increment($column, $amount = 1, array $extra = []) - { - $this->cache($this->makeCacheTags()) - ->flush(); - - return parent::increment($column, $amount, $extra); - } - - public function inRandomOrder($seed = '') - { - $this->isCachable = false; - - return parent::inRandomOrder($seed); - } - - public function insert(array $values) - { - $this->checkCooldownAndFlushAfterPersisting($this->model); - - return parent::insert($values); - } - - public function max($column) - { - if (! $this->isCachable()) { - return parent::max($column); - } - - $cacheKey = $this->makeCacheKey(["*"], null, "-max_{$column}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function min($column) - { - if (! $this->isCachable()) { - return parent::min($column); - } - - $cacheKey = $this->makeCacheKey(["*"], null, "-min_{$column}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function paginate( - $perPage = null, - $columns = ["*"], - $pageName = "page", - $page = null - ) { - if (! $this->isCachable()) { - return parent::paginate($perPage, $columns, $pageName, $page); - } - - $page = app('request')->input($pageName) - ?: $page - ?: 1; - - if (is_array($page)) { - $page = $this->recursiveImplodeWithKey($page); - } - $cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function getRelation($name) - { - $relation = parent::getRelation($name); - - if (! $this->isCachable() - && is_a($relation->getQuery(), self::class) - ) { - $relation->getQuery()->disableModelCaching(); - } - - return $relation; - } - - protected function recursiveImplodeWithKey(array $items, string $glue = "_") : string - { - $result = ""; - - foreach ($items as $key => $value) { - if (is_array($value)) { - $result .= $key . $glue . $this->recursiveImplodeWithKey($value, $glue); - - continue; - } - - $result .= $glue . $key . $glue . $value; - } - - return $result; - } - - public function pluck($column, $key = null) - { - if (! $this->isCachable()) { - return parent::pluck($column, $key); - } - - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); - $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function sum($column) - { - if (! $this->isCachable()) { - return parent::sum($column); - } - - $cacheKey = $this->makeCacheKey(["*"], null, "-sum_{$column}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function update(array $values) - { - $this->checkCooldownAndFlushAfterPersisting($this->model); - - return parent::update($values); - } - - public function value($column) - { - if (! $this->isCachable()) { - return parent::value($column); - } - - $cacheKey = $this->makeCacheKey(["*"], null, "-value_{$column}"); - - return $this->cachedValue(func_get_args(), $cacheKey); - } - - public function cachedValue(array $arguments, string $cacheKey) - { - $method = debug_backtrace()[1]['function']; - $cacheTags = $this->makeCacheTags(); - $hashedCacheKey = sha1($cacheKey); - $result = $this->retrieveCachedValue( - $arguments, - $cacheKey, - $cacheTags, - $hashedCacheKey, - $method - ); - - return $this->preventHashCollision( - $result, - $arguments, - $cacheKey, - $cacheTags, - $hashedCacheKey, - $method - ); - } - - protected function preventHashCollision( - array $result, - array $arguments, - string $cacheKey, - array $cacheTags, - string $hashedCacheKey, - string $method - ) { - if ($result["key"] === $cacheKey) { - return $result["value"]; - } - - $this->cache() - ->tags($cacheTags) - ->forget($hashedCacheKey); - - return $this->retrieveCachedValue( - $arguments, - $cacheKey, - $cacheTags, - $hashedCacheKey, - $method - ); - } - - protected function retrieveCachedValue( - array $arguments, - string $cacheKey, - array $cacheTags, - string $hashedCacheKey, - string $method - ) { - $this->checkCooldownAndRemoveIfExpired($this->model); - - return $this->cache($cacheTags) - ->rememberForever( - $hashedCacheKey, - function () use ($arguments, $cacheKey, $method) { - return [ - "key" => $cacheKey, - "value" => parent::{$method}(...$arguments), - ]; - } - ); - } } diff --git a/src/Traits/Buildable.php b/src/Traits/Buildable.php new file mode 100644 index 0000000..3ff80e1 --- /dev/null +++ b/src/Traits/Buildable.php @@ -0,0 +1,317 @@ +isCachable()) { + return parent::avg($column); + } + + $cacheKey = $this->makeCacheKey(["*"], null, "-avg_{$column}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function count($columns = "*") + { + if (! $this->isCachable()) { + return parent::count($columns); + } + + $cacheKey = $this->makeCacheKey([$columns], null, "-count"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function decrement($column, $amount = 1, array $extra = []) + { + $this->cache($this->makeCacheTags()) + ->flush(); + + return parent::decrement($column, $amount, $extra); + } + + public function delete() + { + $this->cache($this->makeCacheTags()) + ->flush(); + + return parent::delete(); + } + + /** + * @SuppressWarnings(PHPMD.ShortVariable) + */ + public function find($id, $columns = ["*"]) + { + if (! $this->isCachable()) { + return parent::find($id, $columns); + } + + $idKey = collect($id) + ->implode('_'); + $preStr = is_array($id) + ? 'find_list' + : 'find'; + $cacheKey = $this->makeCacheKey($columns, null, "-{$preStr}_{$idKey}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function first($columns = ["*"]) + { + if (! $this->isCachable()) { + return parent::first($columns); + } + + if (! is_array($columns)) { + $columns = [$columns]; + } + + $cacheKey = $this->makeCacheKey($columns, null, "-first"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function forceDelete() + { + $this->cache($this->makeCacheTags()) + ->flush(); + + return parent::forceDelete(); + } + + public function get($columns = ["*"]) + { + if (! $this->isCachable()) { + return parent::get($columns); + } + + $cacheKey = $this->makeCacheKey($columns); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function increment($column, $amount = 1, array $extra = []) + { + $this->cache($this->makeCacheTags()) + ->flush(); + + return parent::increment($column, $amount, $extra); + } + + public function inRandomOrder($seed = '') + { + $this->isCachable = false; + + return parent::inRandomOrder($seed); + } + + public function insert(array $values) + { + $this->checkCooldownAndFlushAfterPersisting($this->model); + + return parent::insert($values); + } + + public function max($column) + { + if (! $this->isCachable()) { + return parent::max($column); + } + + $cacheKey = $this->makeCacheKey(["*"], null, "-max_{$column}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function min($column) + { + if (! $this->isCachable()) { + return parent::min($column); + } + + $cacheKey = $this->makeCacheKey(["*"], null, "-min_{$column}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function paginate( + $perPage = null, + $columns = ["*"], + $pageName = "page", + $page = null + ) { + if (! $this->isCachable()) { + return parent::paginate($perPage, $columns, $pageName, $page); + } + + $page = app('request')->input($pageName) + ?: $page + ?: 1; + + if (is_array($page)) { + $page = $this->recursiveImplodeWithKey($page); + } + $cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function getRelation($name) + { + $relation = parent::getRelation($name); + + if (! $this->isCachable() + && is_a($relation->getQuery(), self::class) + ) { + $relation->getQuery()->disableModelCaching(); + } + + return $relation; + } + + protected function recursiveImplodeWithKey(array $items, string $glue = "_") : string + { + $result = ""; + + foreach ($items as $key => $value) { + if (is_array($value)) { + $result .= $key . $glue . $this->recursiveImplodeWithKey($value, $glue); + + continue; + } + + $result .= $glue . $key . $glue . $value; + } + + return $result; + } + + public function pluck($column, $key = null) + { + if (! $this->isCachable()) { + return parent::pluck($column, $key); + } + + $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); + $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function sum($column) + { + if (! $this->isCachable()) { + return parent::sum($column); + } + + $cacheKey = $this->makeCacheKey(["*"], null, "-sum_{$column}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function update(array $values) + { + $this->checkCooldownAndFlushAfterPersisting($this->model); + + return parent::update($values); + } + + public function value($column) + { + if (! $this->isCachable()) { + return parent::value($column); + } + + $cacheKey = $this->makeCacheKey(["*"], null, "-value_{$column}"); + + return $this->cachedValue(func_get_args(), $cacheKey); + } + + public function cachedValue(array $arguments, string $cacheKey) + { + $method = debug_backtrace()[1]['function']; + $cacheTags = $this->makeCacheTags(); + $hashedCacheKey = sha1($cacheKey); + $result = $this->retrieveCachedValue( + $arguments, + $cacheKey, + $cacheTags, + $hashedCacheKey, + $method + ); + + return $this->preventHashCollision( + $result, + $arguments, + $cacheKey, + $cacheTags, + $hashedCacheKey, + $method + ); + } + + protected function preventHashCollision( + array $result, + array $arguments, + string $cacheKey, + array $cacheTags, + string $hashedCacheKey, + string $method + ) { + if ($result["key"] === $cacheKey) { + return $result["value"]; + } + + $this->cache() + ->tags($cacheTags) + ->forget($hashedCacheKey); + + return $this->retrieveCachedValue( + $arguments, + $cacheKey, + $cacheTags, + $hashedCacheKey, + $method + ); + } + + protected function retrieveCachedValue( + array $arguments, + string $cacheKey, + array $cacheTags, + string $hashedCacheKey, + string $method + ) { + $model = new BaseModel; + + if (property_exists($this, "model")) { + $model = $this->model; + } + + if (\method_exists($this, "getModel")) { + $model = $this->getModel(); + } + + $this->checkCooldownAndRemoveIfExpired($model); + + return $this->cache($cacheTags) + ->rememberForever( + $hashedCacheKey, + function () use ($arguments, $cacheKey, $method) { + return [ + "key" => $cacheKey, + "value" => parent::{$method}(...$arguments), + ]; + } + ); + } +} diff --git a/src/Traits/Cachable.php b/src/Traits/Cachable.php index 7f22e3f..4fa92b0 100644 --- a/src/Traits/Cachable.php +++ b/src/Traits/Cachable.php @@ -4,7 +4,9 @@ trait Cachable { - use PivotEventTrait; use Caching; use ModelCaching; + use PivotEventTrait { + ModelCaching::newBelongsToMany insteadof PivotEventTrait; + } } diff --git a/src/Traits/CachePrefixing.php b/src/Traits/CachePrefixing.php index 56e4925..e97a6dd 100644 --- a/src/Traits/CachePrefixing.php +++ b/src/Traits/CachePrefixing.php @@ -14,7 +14,7 @@ protected function getCachePrefix() : string protected function getDatabaseName() : string { - return $this->model->getConnection()->getDatabaseName(); + return $this->query->getConnection()->getDatabaseName(); } protected function getConnectionName() : string diff --git a/src/Traits/Caching.php b/src/Traits/Caching.php index 5722143..d38d400 100644 --- a/src/Traits/Caching.php +++ b/src/Traits/Caching.php @@ -69,8 +69,16 @@ protected function makeCacheKey( string $keyDifferentiator = '' ) : string { $eagerLoad = $this->eagerLoad ?? []; - $model = $this->model ?? $this; - $query = $this->query ?? app('db')->query(); + $model = $this->model + ?? $this; + $query = $this->query + ?? app('db')->query(); + + if ($this->query + && method_exists($this->query, "getQuery") + ) { + $query = $this->query->getQuery(); + } return (new CacheKey($eagerLoad, $model, $query)) ->make($columns, $idColumn, $keyDifferentiator); @@ -79,8 +87,8 @@ protected function makeCacheKey( protected function makeCacheTags() : array { $eagerLoad = $this->eagerLoad ?? []; - $model = $this->model instanceof Model - ? $this->model + $model = $this->getModel() instanceof Model + ? $this->getModel() : $this; $query = $this->query instanceof Builder ? $this->query diff --git a/src/Traits/ModelCaching.php b/src/Traits/ModelCaching.php index 3c14b8b..9f7252d 100644 --- a/src/Traits/ModelCaching.php +++ b/src/Traits/ModelCaching.php @@ -1,8 +1,10 @@ isCachable()) { diff --git a/tests/Fixtures/BaseModel.php b/tests/Fixtures/BaseModel.php index 1d9ce2e..4c394e3 100644 --- a/tests/Fixtures/BaseModel.php +++ b/tests/Fixtures/BaseModel.php @@ -2,8 +2,6 @@ use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; class BaseModel extends Model { diff --git a/tests/Integration/CachedBuilder/FindOrFailTest.php b/tests/Integration/CachedBuilder/FindOrFailTest.php index e11ec99..c0b932c 100644 --- a/tests/Integration/CachedBuilder/FindOrFailTest.php +++ b/tests/Integration/CachedBuilder/FindOrFailTest.php @@ -1,19 +1,8 @@ findOrFail(1); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-find_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-find_1'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this->cache() diff --git a/tests/Integration/CachedBuilder/FindTest.php b/tests/Integration/CachedBuilder/FindTest.php index a4777a5..e48238f 100644 --- a/tests/Integration/CachedBuilder/FindTest.php +++ b/tests/Integration/CachedBuilder/FindTest.php @@ -1,28 +1,17 @@ push((new Author)->find(1)); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = collect()->push($this->cache()->tags($tags) @@ -37,9 +26,9 @@ public function testFindMultipleModelResultsCreatesCache() { $authors = (new Author) ->find([1, 2, 3]); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-find_list_1_2_3'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-find_list_1_2_3'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this diff --git a/tests/Integration/CachedBuilder/FirstOrCreateTest.php b/tests/Integration/CachedBuilder/FirstOrCreateTest.php index 3fbe0e6..0faef0f 100644 --- a/tests/Integration/CachedBuilder/FirstOrCreateTest.php +++ b/tests/Integration/CachedBuilder/FirstOrCreateTest.php @@ -1,19 +1,7 @@ cache() ->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]) ->get(sha1( - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1' ))["value"]; (new Author) @@ -38,10 +26,10 @@ public function testForceDeleteClearsCache() $resultsAfter = $this ->cache() ->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]) ->get(sha1( - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_=_1' ))["value"]; $this->assertEquals(get_class($resultsBefore), get_class($author)); diff --git a/tests/Integration/CachedBuilder/GetTest.php b/tests/Integration/CachedBuilder/GetTest.php index cda663a..0562d64 100644 --- a/tests/Integration/CachedBuilder/GetTest.php +++ b/tests/Integration/CachedBuilder/GetTest.php @@ -1,19 +1,8 @@ with('books', 'profile') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResults = $this->cache()->tags($tags) ->get($key)['value']; $liveResults = (new UncachedAuthor)->with('books', 'profile') ->get(); -// dd($cachedResults); + $this->assertEquals($authors, $cachedResults); $this->assertEmpty($liveResults->diffKeys($cachedResults)); } @@ -56,9 +45,9 @@ public function testAccessingGetResultsViaArrayIndexDoesNotError() public function testGetWithFieldArrayCachesResults() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $authors = (new Author) diff --git a/tests/Integration/CachedBuilder/InRandomOrderQueryTest.php b/tests/Integration/CachedBuilder/InRandomOrderQueryTest.php index 7985cc1..150be2f 100644 --- a/tests/Integration/CachedBuilder/InRandomOrderQueryTest.php +++ b/tests/Integration/CachedBuilder/InRandomOrderQueryTest.php @@ -1,19 +1,8 @@ first(); -// -// dump("start"); -// $stores = $book->stores; -// dump("end"); -// dd($stores); -// $cachedResults = $this -// ->cache() -// ->tags($tags) -// ->get($key)['value']; -// $liveResults = (new UncachedBook) -// ->when(true, function ($query) { -// $query->where("id", "<", 5); -// }) -// ->get(); -// -// $this->assertEquals($liveResults->pluck("id"), $books->pluck("id")); -// $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); -// } + public function testLazyLoadingRelationshipQuery() + { + $bookId = (new Store) + ->disableModelCaching() + ->with("books") + ->first() + ->books + ->first() + ->id; + $key = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:book-store:genealabslaravelmodelcachingcachedbelongstomany-book_store.book_id_=_{$bookId}"); + $tags = [ + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore', + ]; + + $stores = (new Book) + ->find($bookId) + ->stores; + $cachedStores = $this + ->cache() + ->tags($tags) + ->get($key)['value']; + $uncachedBook = (new UncachedBook) + ->find($bookId); + $uncachedStores = $uncachedBook->stores; + + $this->assertEquals($uncachedStores->pluck("id"), $stores->pluck("id")); + $this->assertEquals($uncachedStores->pluck("id"), $cachedStores->pluck("id")); + $this->assertNotNull($cachedStores); + $this->assertNotNull($uncachedStores); + } } diff --git a/tests/Integration/CachedBuilder/MorphOneTest.php b/tests/Integration/CachedBuilder/MorphOneTest.php index f3af5f6..5ac9696 100644 --- a/tests/Integration/CachedBuilder/MorphOneTest.php +++ b/tests/Integration/CachedBuilder/MorphOneTest.php @@ -22,11 +22,11 @@ public function setUp() : void public function testMorphTo() { - $key1 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_1-testing::memory::image'); - $key2 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_2-testing::memory::image'); + $key1 = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_1-testing::memory::image'); + $key2 = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-author_id_=_2-testing::memory::image'); $tags = [ - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook", - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesimage", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesimage", ]; $books1 = (new Book) diff --git a/tests/Integration/CachedBuilder/PaginateTest.php b/tests/Integration/CachedBuilder/PaginateTest.php index 323d32b..7ac96e0 100644 --- a/tests/Integration/CachedBuilder/PaginateTest.php +++ b/tests/Integration/CachedBuilder/PaginateTest.php @@ -2,17 +2,8 @@ use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -25,9 +16,9 @@ public function testPaginationIsCached() $authors = (new Author) ->paginate(3); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this @@ -158,9 +149,9 @@ public function testPaginationWithCustomOptionsReturnsCorrectLinks() public function testCustomPageNamePagination() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_custom-page_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_custom-page_1'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $authors = (new Author) diff --git a/tests/Integration/CachedBuilder/ScopeTest.php b/tests/Integration/CachedBuilder/ScopeTest.php index 9324467..8c3c176 100644 --- a/tests/Integration/CachedBuilder/ScopeTest.php +++ b/tests/Integration/CachedBuilder/ScopeTest.php @@ -1,19 +1,8 @@ startsWithA() ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_A%'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_A%'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -49,8 +38,8 @@ public function testScopeClauseWithParameter() $authors = (new Author) ->nameStartsWith("B") ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_B%'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_like_B%'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -71,8 +60,8 @@ public function testGlobalScopesAreCached() ->first(); $authors = (new AuthorBeginsWithA) ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthorbeginswitha']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthorbeginswitha']; $cachedResults = $this->cache() ->tags($tags) diff --git a/tests/Integration/CachedBuilder/SelectTest.php b/tests/Integration/CachedBuilder/SelectTest.php index 9519602..cafe327 100644 --- a/tests/Integration/CachedBuilder/SelectTest.php +++ b/tests/Integration/CachedBuilder/SelectTest.php @@ -1,27 +1,15 @@ raw("author_id"), @@ -52,9 +40,9 @@ public function testSelectWithRawColumns() // public function testSelectFieldsAreCached() // { - // $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first'); + // $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-first'); // $tags = [ - // 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + // 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', // ]; // $authorFields = (new Author) diff --git a/tests/Integration/CachedBuilder/SoftDeletesTest.php b/tests/Integration/CachedBuilder/SoftDeletesTest.php index d0dd842..194cb2a 100644 --- a/tests/Integration/CachedBuilder/SoftDeletesTest.php +++ b/tests/Integration/CachedBuilder/SoftDeletesTest.php @@ -1,27 +1,16 @@ first(); @@ -44,9 +33,9 @@ public function testWithTrashedIsCached() // public function testWithoutTrashedIsCached() // { - // $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1-first'); + // $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1-first'); // $tags = [ - // 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + // 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', // ]; // $author = (new UncachedAuthor) // ->first(); diff --git a/tests/Integration/CachedBuilder/UpdateExistingPivotTest.php b/tests/Integration/CachedBuilder/UpdateExistingPivotTest.php index d58b575..15b8e0f 100644 --- a/tests/Integration/CachedBuilder/UpdateExistingPivotTest.php +++ b/tests/Integration/CachedBuilder/UpdateExistingPivotTest.php @@ -1,19 +1,7 @@ where("id", "<", 5) @@ -35,9 +35,9 @@ public function testWhereInUsingCollectionQuery() public function testWhereInWhenSetIsEmpty() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $authors = (new Author) ->whereIn("id", []) @@ -56,9 +56,9 @@ public function testWhereInWhenSetIsEmpty() public function testBindingsAreCorrectWithMultipleWhereInClauses() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_in_John-id_in_-name_in_Mike'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_in_John-id_in_-name_in_Mike'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $authors = (new Author) ->whereIn("name", ["John"]) @@ -81,8 +81,8 @@ public function testBindingsAreCorrectWithMultipleWhereInClauses() public function testWhereInUsesCorrectBindings() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_1_2_3_4_5-id_between_1_99999'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_in_1_2_3_4_5-id_between_1_99999'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new Author) ->whereIn('id', [1,2,3,4,5]) diff --git a/tests/Integration/CachedBuilder/WhereJsonContainsTest.php b/tests/Integration/CachedBuilder/WhereJsonContainsTest.php index 6e89412..4ae28f1 100644 --- a/tests/Integration/CachedBuilder/WhereJsonContainsTest.php +++ b/tests/Integration/CachedBuilder/WhereJsonContainsTest.php @@ -1,20 +1,9 @@ total_jsoncontains_5000'); + $key = sha1('genealabs:laravel-model-caching:pgsql:testing:test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->total_jsoncontains_5000'); $tags = [ - 'genealabs:laravel-model-caching:pgsql:testing:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:pgsql:testing:test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $authors = (new Author) diff --git a/tests/Integration/CachedBuilder/WhereNotInTest.php b/tests/Integration/CachedBuilder/WhereNotInTest.php index 07979ba..f4b78cf 100644 --- a/tests/Integration/CachedBuilder/WhereNotInTest.php +++ b/tests/Integration/CachedBuilder/WhereNotInTest.php @@ -1,27 +1,17 @@ where("id", "<", 5) @@ -44,9 +34,9 @@ public function testWhereNotInQuery() public function testWhereNotInResults() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $results = (new Book) @@ -65,9 +55,9 @@ public function testWhereNotInResults() public function testWhereNotInSubquery() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_select_id_from_authors_where_id_<_10'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_select_id_from_authors_where_id_<_10'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $results = (new Book) ->whereNotIn("id", function ($query) { diff --git a/tests/Integration/CachedBuilder/WhereNullTest.php b/tests/Integration/CachedBuilder/WhereNullTest.php index f9c8a5f..95a32a1 100644 --- a/tests/Integration/CachedBuilder/WhereNullTest.php +++ b/tests/Integration/CachedBuilder/WhereNullTest.php @@ -1,19 +1,8 @@ whereRaw('name <> \'\'') ->first()]); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_and_name-first'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_and_name-first'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = collect([$this->cache()->tags($tags)->get($key)['value']]); @@ -43,8 +34,8 @@ public function testWhereRawWithQueryParameters() ->whereRaw("name != 'test3'") ->whereRaw('name = ? AND name != ?', [$authorName, "test2"]) ->get(); - $key = sha1("genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthorname_!=_test_and_name_!=_'test3'_and_name_=_Guido_Feest__AND_name_!=_test2"); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthorname_!=_test_and_name_!=_'test3'_and_name_=_Guido_Feest__AND_name_!=_test2"); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = collect([$this->cache()->tags($tags)->get($key)['value']]); $liveResults = (new UncachedAuthor) @@ -114,9 +105,9 @@ public function testWhereRawParametersCacheUniquely() $result2 = (new Book) ->whereRaw("id = ?", [$book2->id]) ->get(); - $key1 = sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-_and_id_=_{$book1->id}"); - $key2 = sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-_and_id_=_{$book2->id}"); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook']; + $key1 = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-_and_id_=_{$book1->id}"); + $key2 = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-_and_id_=_{$book2->id}"); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook']; $cachedBook1 = $this->cache()->tags($tags)->get($key1)['value']; $cachedBook2 = $this->cache()->tags($tags)->get($key2)['value']; @@ -137,9 +128,9 @@ public function testWhereRawParametersAfterWhereClause() ->where("id", ">", 1) ->whereRaw("id = ?", [$book2->id]) ->get(); - $key1 = sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_>_0-_and_id_=_{$book1->id}"); - $key2 = sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_>_1-_and_id_=_{$book2->id}"); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook']; + $key1 = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_>_0-_and_id_=_{$book1->id}"); + $key2 = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_>_1-_and_id_=_{$book2->id}"); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook']; $cachedBook1 = $this->cache()->tags($tags)->get($key1)['value']; $cachedBook2 = $this->cache()->tags($tags)->get($key2)['value']; diff --git a/tests/Integration/CachedBuilder/WhereTest.php b/tests/Integration/CachedBuilder/WhereTest.php index 454bfe3..f175357 100644 --- a/tests/Integration/CachedBuilder/WhereTest.php +++ b/tests/Integration/CachedBuilder/WhereTest.php @@ -2,18 +2,9 @@ use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Support\Collection; class WhereTest extends IntegrationTestCase { @@ -43,9 +34,9 @@ public function testColumnsRelationshipWhereClauseParsing() $authors = (new Author) ->where('name', '=', $author->name) ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name_=_' . + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name_=_' . $author->name); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -65,14 +56,14 @@ private function processWhereClauseTestWithOperator(string $operator) ->where('name', $operator, $author->name) ->get(); $keyParts = [ - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-name', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-name', '_', str_replace(' ', '_', strtolower($operator)), '_', $author->name, ]; $key = sha1(implode('', $keyParts)); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -98,8 +89,8 @@ public function testWhereClauseParsingOfOperators() public function testTwoWhereClausesAfterEachOther() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_>_0-id_<_100'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_>_0-id_<_100'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new Author) ->where("id", ">", 0) @@ -119,8 +110,8 @@ public function testTwoWhereClausesAfterEachOther() public function testWhereUsesCorrectBinding() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-id_>_5-name_like_B%'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-id_>_5-name_like_B%'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new Author) ->where("id", ">", 2) diff --git a/tests/Integration/CachedBuilder/WithCountTest.php b/tests/Integration/CachedBuilder/WithCountTest.php index 7bf239e..f023fe4 100644 --- a/tests/Integration/CachedBuilder/WithCountTest.php +++ b/tests/Integration/CachedBuilder/WithCountTest.php @@ -3,19 +3,8 @@ use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Comment; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedComment; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Support\Collection; class WithCountTest extends IntegrationTestCase { diff --git a/tests/Integration/CachedBuilder/WithTest.php b/tests/Integration/CachedBuilder/WithTest.php index 8c367ee..606477e 100644 --- a/tests/Integration/CachedBuilder/WithTest.php +++ b/tests/Integration/CachedBuilder/WithTest.php @@ -2,18 +2,9 @@ use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Support\Collection; class WithTest extends IntegrationTestCase { @@ -63,10 +54,10 @@ public function testMultiLevelWithQuery() public function testWithBelongsToManyRelationshipQuery() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-books.id_=_3-testing::memory::stores-first'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-books.id_=_3-testing::memory::stores-first'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore', ]; $stores = (new Book) diff --git a/tests/Integration/CachedBuilderMultipleQueryTest.php b/tests/Integration/CachedBuilderMultipleQueryTest.php index 571f12e..e9d3a9c 100644 --- a/tests/Integration/CachedBuilderMultipleQueryTest.php +++ b/tests/Integration/CachedBuilderMultipleQueryTest.php @@ -1,18 +1,7 @@ with("stores") ->has("stores") ->get(); - $key = "genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-exists-and_books.id_=_book_store.book_id-testing::memory::stores"; + $key = "genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-exists-and_books.id_=_book_store.book_id-testing::memory::stores"; $tags = [ - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook", - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore", ]; $cachedResults = $this ->cache() diff --git a/tests/Integration/CachedBuilderTest.php b/tests/Integration/CachedBuilderTest.php index d83ef04..d4fb9d3 100644 --- a/tests/Integration/CachedBuilderTest.php +++ b/tests/Integration/CachedBuilderTest.php @@ -2,17 +2,9 @@ use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; -use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource; use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) @@ -23,10 +15,10 @@ class CachedBuilderTest extends IntegrationTestCase public function testCacheIsEmptyBeforeLoadingModels() { $results = $this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) - ->get('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books'); + ->get('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::test-prefix:books'); $this->assertNull($results); } @@ -36,10 +28,10 @@ public function testCacheIsNotEmptyAfterLoadingModels() (new Author)->with('books')->get(); $results = $this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) - ->get(sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books')); + ->get(sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books')); $this->assertNotNull($results); } @@ -51,12 +43,12 @@ public function testCreatingModelClearsCache() factory(Author::class)->create(); $results = $this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) ->get(sha1( - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . - '7_8_9_10-genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbooks' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . + '7_8_9_10-genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbooks' )); $this->assertNull($results); @@ -69,12 +61,12 @@ public function testUpdatingModelClearsCache() $author->save(); $results = $this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) ->get(sha1( - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . - '7_8_9_10-genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbooks' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . + '7_8_9_10-genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbooks' )); $this->assertNull($results); @@ -86,12 +78,12 @@ public function testDeletingModelClearsCache() $author->delete(); $results = $this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) ->get(sha1( - 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . - '7_8_9_10-genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbooks' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_' . + '7_8_9_10-genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbooks' )); $this->assertNull($results); @@ -102,10 +94,10 @@ public function testHasManyRelationshipIsCached() $authors = (new Author)->with('books')->get(); $results = collect($this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]) - ->get(sha1("genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books"))['value']); + ->get(sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books"))['value']); $this->assertNotNull($results); $this->assertEmpty($authors->diffKeys($results)); @@ -119,10 +111,10 @@ public function testBelongsToRelationshipIsCached() $books = (new Book)->with('author')->get(); $results = collect($this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor' ]) - ->get(sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-testing::memory::author"))['value']); + ->get(sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-testing::memory::author"))['value']); $this->assertNotNull($results); $this->assertEmpty($books->diffKeys($results)); @@ -136,10 +128,10 @@ public function testBelongsToManyRelationshipIsCached() $books = (new Book)->with('stores')->get(); $results = collect($this->cache()->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore' ]) - ->get(sha1("genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-testing::memory::stores"))['value']); + ->get(sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-testing::memory::stores"))['value']); $this->assertNotNull($results); $this->assertEmpty($books->diffKeys($results)); @@ -154,10 +146,10 @@ public function testHasOneRelationshipIsCached() $results = collect($this->cache() ->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile' ]) - ->get(sha1("genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::profile"))['value']); + ->get(sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::profile"))['value']); $this->assertNotNull($results); $this->assertEmpty($authors->diffKeys($results)); @@ -170,11 +162,11 @@ public function testAvgModelResultsCreatesCache() { $authorId = (new Author)->with('books', 'profile') ->avg('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-avg_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-avg_id'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResult = $this->cache() @@ -191,7 +183,7 @@ public function testChunkModelResultsCreatesCache() { $chunkedAuthors = []; $chunkedKeys = []; - $tags = ["genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor"]; + $tags = ["genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor"]; (new Author) ->chunk(3, function ($authors) use (&$chunkedAuthors, &$chunkedKeys) { $offset = ""; @@ -200,7 +192,7 @@ public function testChunkModelResultsCreatesCache() $offset = "-offset_" . (count($chunkedKeys) * 3); } - $key = "genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_orderBy_authors.id_asc{$offset}-limit_3"; + $key = "genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_orderBy_authors.id_asc{$offset}-limit_3"; array_push($chunkedAuthors, $authors); array_push($chunkedKeys, $key); }); @@ -224,11 +216,11 @@ public function testCountModelResultsCreatesCache() $authors = (new Author) ->with('books', 'profile') ->count(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-count'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-count'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResults = $this->cache()->tags($tags) @@ -246,11 +238,11 @@ public function testCountWithStringCreatesCache() $authors = (new Author) ->with('books', 'profile') ->count("id"); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_id-testing::memory::books-testing::memory::profile-count'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_id-testing::memory::books-testing::memory::profile-count'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResults = $this->cache()->tags($tags) @@ -267,9 +259,9 @@ public function testFirstModelResultsCreatesCache() { $author = (new Author) ->first(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-first'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-first'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResult = $this->cache()->tags($tags) @@ -287,11 +279,11 @@ public function testMaxModelResultsCreatesCache() { $authorId = (new Author)->with('books', 'profile') ->max('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-max_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-max_id'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResult = $this->cache()->tags($tags) @@ -307,11 +299,11 @@ public function testMinModelResultsCreatesCache() { $authorId = (new Author)->with('books', 'profile') ->min('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-min_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-min_id'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResult = $this->cache()->tags($tags) @@ -327,11 +319,11 @@ public function testPluckModelResultsCreatesCache() { $authors = (new Author)->with('books', 'profile') ->pluck('name', 'id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-pluck_name_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-pluck_name_id'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResults = $this->cache()->tags($tags) @@ -347,11 +339,11 @@ public function testSumModelResultsCreatesCache() { $authorId = (new Author)->with('books', 'profile') ->sum('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-sum_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-sum_id'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResult = $this->cache()->tags($tags) @@ -367,11 +359,11 @@ public function testValueModelResultsCreatesCache() { $authorName = (new Author)->with('books', 'profile') ->value('name'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-value_name'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-value_name'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesprofile', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesprofile', ]; $cachedResult = $this->cache()->tags($tags) @@ -388,11 +380,11 @@ public function testNestedRelationshipEagerLoading() $authors = collect([(new Author)->with('books.publisher') ->first()]); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::books.publisher-first'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::books.publisher-first'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturespublisher', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturespublisher', ]; $cachedResults = collect([$this->cache()->tags($tags) @@ -407,9 +399,9 @@ public function testNestedRelationshipEagerLoading() public function testLazyLoadedRelationshipResolvesThroughCachedBuilder() { $books = (new Author)->first()->books; - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache() @@ -428,9 +420,9 @@ public function testLazyLoadingOnResourceIsCached() } $books = (new AuthorResource((new Author)->first()))->books; - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache() @@ -446,9 +438,9 @@ public function testOrderByClauseParsing() { $authors = (new Author)->orderBy('name')->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_orderBy_name_asc'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_orderBy_name_asc'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this->cache() @@ -466,11 +458,11 @@ public function testNestedRelationshipWhereClauseParsing() ->with('books.publisher') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-books.publisher'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-books.publisher'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturespublisher', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturespublisher', ]; $cachedResults = $this->cache() @@ -489,8 +481,8 @@ public function testExistsRelationshipWhereClauseParsing() $authors = (new Author)->whereHas('books') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-exists-and_authors.id_=_books.author_id'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-exists-and_authors.id_=_books.author_id'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -508,8 +500,8 @@ public function testDoesntHaveWhereClauseParsing() ->doesntHave('books') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_notexists_and_authors.id_=_books.author_id'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_notexists_and_authors.id_=_books.author_id'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -528,9 +520,9 @@ public function testRelationshipQueriesAreCached() ->first() ->books() ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-books.author_id_=_1-books.author_id_notnull'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook' + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook' ]; $cachedResults = $this->cache() @@ -551,8 +543,8 @@ public function testRawOrderByWithoutColumnReference() ->orderByRaw('DATE()') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_orderByRaw_date'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_orderByRaw_date'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this->cache() ->tags($tags) @@ -574,8 +566,8 @@ public function testDelete() ->first(); $authorId = $author->id; $liveResultId = $liveResult->id; - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $author->delete(); $liveResult->delete(); @@ -594,9 +586,9 @@ public function testWhereBetweenIdsResults() $books = (new Book) ->whereBetween('price', [5, 10]) ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-price_between_5_10'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-price_between_5_10'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache() @@ -615,9 +607,9 @@ public function testWhereBetweenDatesResults() $books = (new Book) ->whereBetween('created_at', ['2018-01-01', '2018-12-31']) ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-created_at_between_2018-01-01_2018-12-31'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-created_at_between_2018-01-01_2018-12-31'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache() @@ -636,9 +628,9 @@ public function testWhereDatesResults() $books = (new Book) ->whereDate('created_at', '>=', '2018-01-01') ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-created_at_>=_2018-01-01'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-created_at_>=_2018-01-01'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache() @@ -654,8 +646,8 @@ public function testWhereDatesResults() public function testHashCollision() { - $key1 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2'); - $tags1 = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook']; + $key1 = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2'); + $tags1 = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook']; $books = (new Book) ->whereNotIn('id', [1, 2]) ->get(); @@ -664,7 +656,7 @@ public function testHashCollision() $authors = (new Author) ->disableCache() ->get(); - $key2 = 'genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'; + $key2 = 'genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'; $this->cache() ->tags($tags1) ->rememberForever( @@ -690,8 +682,8 @@ function () use ($key2, $authors) { public function testSubsequentDisabledCacheQueriesDoNotCache() { (new Author)->disableCache()->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedAuthors1 = $this->cache() ->tags($tags) ->get($key)['value']; diff --git a/tests/Integration/CachedModelTest.php b/tests/Integration/CachedModelTest.php index c686f00..68e88c5 100644 --- a/tests/Integration/CachedModelTest.php +++ b/tests/Integration/CachedModelTest.php @@ -13,9 +13,9 @@ class CachedModelTest extends IntegrationTestCase public function testAllModelResultsCreatesCache() { $authors = (new Author)->all(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this @@ -31,8 +31,8 @@ public function testAllModelResultsCreatesCache() public function testScopeDisablesCaching() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new Author) ->where("name", "Bruno") ->disableCache() @@ -48,8 +48,8 @@ public function testScopeDisablesCaching() public function testScopeDisablesCachingWhenCalledOnModel() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new PrefixedAuthor) ->disableCache() ->where("name", "Bruno") @@ -66,8 +66,8 @@ public function testScopeDisablesCachingWhenCalledOnModel() public function testScopeDisableCacheDoesntCrashWhenCachingIsDisabledInConfig() { config(['laravel-model-caching.disabled' => true]); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new PrefixedAuthor) ->where("name", "Bruno") ->disableCache() @@ -86,9 +86,9 @@ public function testAllMethodCachingCanBeDisabledViaConfig() config(['laravel-model-caching.disabled' => true]); $authors = (new Author) ->all(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; config(['laravel-model-caching.disabled' => false]); @@ -111,10 +111,10 @@ public function testWhereHasIsBeingCached() }) ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-exists-and_books.author_id_=_authors.id-id_=_1-authors.deleted_at_null-testing::memory::author'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook-exists-and_books.author_id_=_authors.id-id_=_1-authors.deleted_at_null-testing::memory::author'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this diff --git a/tests/Integration/Console/Commands/FlushTest.php b/tests/Integration/Console/Commands/FlushTest.php index 21c053f..500940f 100644 --- a/tests/Integration/Console/Commands/FlushTest.php +++ b/tests/Integration/Console/Commands/FlushTest.php @@ -21,8 +21,8 @@ public function setUp() : void public function testGivenModelIsFlushed() { $authors = (new Author)->all(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedResults = $this ->cache @@ -69,10 +69,10 @@ public function testExtendedModelIsFlushed() public function testGivenModelWithRelationshipIsFlushed() { $authors = (new Author)->with('books')->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook', ]; $cachedResults = $this->cache @@ -109,18 +109,18 @@ public function testAllModelsAreFlushed() (new Book)->all(); (new Store)->all(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedAuthors = $this->cache ->tags($tags) ->get($key)['value']; - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook']; $cachedBooks = $this->cache ->tags($tags) ->get($key)['value']; - $key = sha1('genealabs:laravel-model-caching:testing::memory::stores:genealabslaravelmodelcachingtestsfixturesstore'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:stores:genealabslaravelmodelcachingtestsfixturesstore'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore']; $cachedStores = $this->cache ->tags($tags) ->get($key)['value']; @@ -132,18 +132,18 @@ public function testAllModelsAreFlushed() $this->artisan('modelCache:clear') ->execute(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $cachedAuthors = $this->cache ->tags($tags) ->get($key)['value']; - $key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:books:genealabslaravelmodelcachingtestsfixturesbook'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook']; $cachedBooks = $this->cache ->tags($tags) ->get($key)['value']; - $key = sha1('genealabs:laravel-model-caching:testing::memory::stores:genealabslaravelmodelcachingtestsfixturesstore'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesstore']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:stores:genealabslaravelmodelcachingtestsfixturesstore'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesstore']; $cachedStores = $this->cache ->tags($tags) ->get($key)['value']; diff --git a/tests/Integration/DisabledCachedBuilderTest.php b/tests/Integration/DisabledCachedBuilderTest.php index fd103c7..eccfc98 100644 --- a/tests/Integration/DisabledCachedBuilderTest.php +++ b/tests/Integration/DisabledCachedBuilderTest.php @@ -1,18 +1,8 @@ with('books', 'profile') ->disableCache() ->avg('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-avg_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-avg_id'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -70,7 +60,7 @@ public function testChunkModelResultsIsNotCached() $cachedChunks['authors']->push($chunk); $cachedChunks['keys']->push(sha1( - "genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile_orderBy_authors.id_asc{$offset}-limit_3" + "genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile_orderBy_authors.id_asc{$offset}-limit_3" )); }); @@ -96,7 +86,7 @@ public function testCountModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->count(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-count'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-count'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -120,7 +110,7 @@ public function testCursorModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->cursor(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-cursor'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-cursor'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -146,7 +136,7 @@ public function testFindModelResultsIsNotCached() ->with('books') ->disableCache() ->find(1); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_1'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', ]; @@ -167,7 +157,7 @@ public function testGetModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->get(); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -191,7 +181,7 @@ public function testMaxModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->max('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-max_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-max_id'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -215,7 +205,7 @@ public function testMinModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->min('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-min_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-min_id'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -239,7 +229,7 @@ public function testPluckModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->pluck('name', 'id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-pluck_name_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-pluck_name_id'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -263,7 +253,7 @@ public function testSumModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->sum('id'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-sum_id'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books-testing::memory::profile-sum_id'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -287,7 +277,7 @@ public function testValueModelResultsIsNotCached() ->with('books', 'profile') ->disableCache() ->value('name'); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-first'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor_name-testing::memory::books-testing::memory::profile-first'); $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', @@ -312,9 +302,9 @@ public function testPaginationIsCached() ->disableCache() ->paginate(3); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1'); $tags = [ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]; $cachedResults = $this->cache() diff --git a/tests/Integration/DisabledCachedModelTest.php b/tests/Integration/DisabledCachedModelTest.php index 90ac5bf..a6a9e08 100644 --- a/tests/Integration/DisabledCachedModelTest.php +++ b/tests/Integration/DisabledCachedModelTest.php @@ -1,24 +1,15 @@ disableCache() ->get(); @@ -35,10 +26,10 @@ public function testCacheCanBeDisabledOnModel() public function testCacheCanBeDisabledOnQuery() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books'); + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor-testing::memory::books'); $tags = [ - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor", - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesbook", ]; $authors = (new Author) ->with('books') diff --git a/tests/Integration/HelperTest.php b/tests/Integration/HelperTest.php index f922c07..fc4cc40 100644 --- a/tests/Integration/HelperTest.php +++ b/tests/Integration/HelperTest.php @@ -8,8 +8,8 @@ class HelperTest extends IntegrationTestCase { public function testClosureRunsWithCacheDisabled() { - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = app("model-cache")->runDisabled(function () { return (new Author) diff --git a/tests/Integration/Traits/BuilderCachingTest.php b/tests/Integration/Traits/BuilderCachingTest.php index 792e50d..d126a6b 100644 --- a/tests/Integration/Traits/BuilderCachingTest.php +++ b/tests/Integration/Traits/BuilderCachingTest.php @@ -22,9 +22,9 @@ public function testDisablingAllQuery() $allAuthors = (new Author) ->disableCache() ->all(); - $key = sha1("genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor"); + $key = sha1("genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor"); $tags = [ - "genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor", + "genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor", ]; $cachedAuthors = $this ->cache() diff --git a/tests/Integration/Traits/CachableTest.php b/tests/Integration/Traits/CachableTest.php index 22f9e5c..4220586 100644 --- a/tests/Integration/Traits/CachableTest.php +++ b/tests/Integration/Traits/CachableTest.php @@ -24,8 +24,8 @@ public function testSpecifyingAlternateCacheDriver() // TODO: make sure the alternate cache is actually loaded config(['cache.stores' => $configCacheStores]); config(['laravel-model-caching.store' => 'customCache']); - $key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'); - $tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor']; + $key = sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'); + $tags = ['genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor']; $authors = (new Author) ->all(); @@ -67,9 +67,9 @@ public function testAllReturnsCollection() $cachedResults = $this ->cache() ->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]) - ->get(sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor'))['value']; + ->get(sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor'))['value']; $liveResults = (new UncachedAuthor)->all(); $this->assertInstanceOf(Collection::class, $authors); @@ -85,9 +85,9 @@ public function testsCacheFlagDisablesCaching() $cachedAuthors = $this ->cache() ->tags([ - 'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor', + 'genealabs:laravel-model-caching:testing::memory::test-prefix:genealabslaravelmodelcachingtestsfixturesauthor', ]) - ->get(sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor')); + ->get(sha1('genealabs:laravel-model-caching:testing::memory::test-prefix:authors:genealabslaravelmodelcachingtestsfixturesauthor')); config(['laravel-model-caching.disabled' => false]);