From 2a8f7057f13462d1176f7b82be5d036d9357d4ac Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sat, 23 Nov 2019 08:58:10 +0200 Subject: [PATCH] wip. --- database/factories/KidFactory.php | 19 +++++++++++ src/Query/Builder.php | 7 ++-- tests/MethodsTest.php | 11 +++++++ tests/Models/Kid.php | 15 +++++++++ tests/TestCase.php | 1 + .../migrations/2018_07_14_183253_kids.php | 32 +++++++++++++++++++ 6 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 database/factories/KidFactory.php create mode 100644 tests/Models/Kid.php create mode 100644 tests/database/migrations/2018_07_14_183253_kids.php diff --git a/database/factories/KidFactory.php b/database/factories/KidFactory.php new file mode 100644 index 0000000..40c3815 --- /dev/null +++ b/database/factories/KidFactory.php @@ -0,0 +1,19 @@ +define(\Rennokki\QueryCache\Test\Models\Kid::class, function () { + return [ + 'name' => 'Kid'.Str::random(5), + ]; +}); diff --git a/src/Query/Builder.php b/src/Query/Builder.php index cda817d..1ad3497 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -78,7 +78,6 @@ protected function getFromQueryCache(string $method = 'get', $columns = ['*']) } $key = $this->getCacheKey('get'); - $seconds = $this->cacheTime; $cache = $this->getCache(); $callback = $this->getQueryCacheCallback($method, $columns); @@ -202,12 +201,12 @@ protected function getCache() /** * Indicate that the query results should be cached. * - * @param \DateTime|int $seconds + * @param \DateTime|int $time * @return \Rennokki\QueryCache\Query\Builder */ - public function cacheFor($seconds) + public function cacheFor($time) { - $this->cacheTime = $seconds; + $this->cacheTime = $time; return $this; } diff --git a/tests/MethodsTest.php b/tests/MethodsTest.php index 12cc514..a6a6efd 100644 --- a/tests/MethodsTest.php +++ b/tests/MethodsTest.php @@ -2,7 +2,9 @@ namespace Rennokki\QueryCache\Test; +use DB; use Cache; +use Rennokki\QueryCache\Test\Models\Kid; use Rennokki\QueryCache\Test\Models\Post; class MethodsTest extends TestCase @@ -68,4 +70,13 @@ public function test_cache_flush_without_the_right_tag() $cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); $this->assertNotNull($cache); } + + public function test_hashed_key() + { + $kid = factory(Kid::class)->create(); + $storedKid = Kid::cacheFor(now()->addHours(1))->first(); + $cache = Cache::get('leqc:156667fa9bcb7fb8abb01018568648406f251ef65736e89e6fd27d08bc48b5bb'); + + $this->assertNotNull($cache); + } } diff --git a/tests/Models/Kid.php b/tests/Models/Kid.php new file mode 100644 index 0000000..453e09f --- /dev/null +++ b/tests/Models/Kid.php @@ -0,0 +1,15 @@ +set('auth.providers.users.model', User::class); $app['config']->set('auth.providers.posts.model', Post::class); + $app['config']->set('auth.providers.kids.model', Kid::class); $app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD'); } diff --git a/tests/database/migrations/2018_07_14_183253_kids.php b/tests/database/migrations/2018_07_14_183253_kids.php new file mode 100644 index 0000000..dcc6085 --- /dev/null +++ b/tests/database/migrations/2018_07_14_183253_kids.php @@ -0,0 +1,32 @@ +increments('id'); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('kids'); + } +}