Skip to content

Commit 2a8f705

Browse files
committed
wip.
1 parent 2563824 commit 2a8f705

File tree

6 files changed

+81
-4
lines changed

6 files changed

+81
-4
lines changed

database/factories/KidFactory.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/*
3+
|--------------------------------------------------------------------------
4+
| Model Factories
5+
|--------------------------------------------------------------------------
6+
|
7+
| This directory should contain each of the model factory definitions for
8+
| your application. Factories provide a convenient way to generate new
9+
| model instances for testing / seeding your application's database.
10+
|
11+
*/
12+
13+
use Illuminate\Support\Str;
14+
15+
$factory->define(\Rennokki\QueryCache\Test\Models\Kid::class, function () {
16+
return [
17+
'name' => 'Kid'.Str::random(5),
18+
];
19+
});

src/Query/Builder.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ protected function getFromQueryCache(string $method = 'get', $columns = ['*'])
7878
}
7979

8080
$key = $this->getCacheKey('get');
81-
$seconds = $this->cacheTime;
8281
$cache = $this->getCache();
8382
$callback = $this->getQueryCacheCallback($method, $columns);
8483

@@ -202,12 +201,12 @@ protected function getCache()
202201
/**
203202
* Indicate that the query results should be cached.
204203
*
205-
* @param \DateTime|int $seconds
204+
* @param \DateTime|int $time
206205
* @return \Rennokki\QueryCache\Query\Builder
207206
*/
208-
public function cacheFor($seconds)
207+
public function cacheFor($time)
209208
{
210-
$this->cacheTime = $seconds;
209+
$this->cacheTime = $time;
211210

212211
return $this;
213212
}

tests/MethodsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5+
use DB;
56
use Cache;
7+
use Rennokki\QueryCache\Test\Models\Kid;
68
use Rennokki\QueryCache\Test\Models\Post;
79

810
class MethodsTest extends TestCase
@@ -68,4 +70,13 @@ public function test_cache_flush_without_the_right_tag()
6870
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}');
6971
$this->assertNotNull($cache);
7072
}
73+
74+
public function test_hashed_key()
75+
{
76+
$kid = factory(Kid::class)->create();
77+
$storedKid = Kid::cacheFor(now()->addHours(1))->first();
78+
$cache = Cache::get('leqc:156667fa9bcb7fb8abb01018568648406f251ef65736e89e6fd27d08bc48b5bb');
79+
80+
$this->assertNotNull($cache);
81+
}
7182
}

tests/Models/Kid.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rennokki\QueryCache\Test\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Rennokki\QueryCache\Traits\QueryCacheable;
7+
8+
class Kid extends Model
9+
{
10+
use QueryCacheable;
11+
12+
protected $fillable = [
13+
'name',
14+
];
15+
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getEnvironmentSetUp($app)
3838
]);
3939
$app['config']->set('auth.providers.users.model', User::class);
4040
$app['config']->set('auth.providers.posts.model', Post::class);
41+
$app['config']->set('auth.providers.kids.model', Kid::class);
4142
$app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD');
4243
}
4344

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class Kids extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('kids', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::dropIfExists('kids');
31+
}
32+
}

0 commit comments

Comments
 (0)