andersao / andersao/l5-repository

`CacheableRepository::getCacheKey()` always returns different key

オープン
#202 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
verify
主要言語
PHP
スター
4.2k
フォーク
880
PR マージ指標
30日以内にマージされた PR はありません

説明

I'm playing around with this great repo. While trying out the cache, I can't get models from cache. So i've made a quick hack to the class' `find()` method:

``` php
public function find($id, $columns = ['*'])
{
if (!$this->allowedCache('find') || $this->isSkippedCache()) {
return parent::find($id, $columns);
}

// just a quick hack to capture the generated cache key
$this->ppkey = $key = $this->getCacheKey('find', func_get_args());
$minutes = $this->getCacheMinutes();
$value = $this->getCacheRepository()->remember($key, $minutes, function () use ($id, $columns) {
return parent::find($id, $columns);
});

return $value;
}
```

In another phpunit file to test it out:

``` php
public function testFind()
{
$repo = new SomeRepositoryEloquent(app());
$model = \App\Repositories\Entities\Client::find(1);
$client1 = $repo->find(1);
$o = $repo->ppkey;

$client2 = $repo->find(1);
$n = $repo->ppkey;

// some asserts to play along with $model, $client1, and $client2

$this->assertTrue(\Cache::has($o)); // passes
$this->assertTrue(\Cache::has($n)); // passes

$this->assertEquals($o, $n); // fails
}
```

After a bit of tracing, I've notice that `serializeCriteria()` tries to simply serialize the criteria, which in my case, is a simple `RequestCriteria`. Looks fine as it may, the `$request` property in `RequestCriteria` holds the whole set of environment, and serialized to different string each time.

Am I doing anything wrong?

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。