andersao / andersao/l5-repository
`CacheableRepository::getCacheKey()` always returns different key
- 主要言語
- 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 はまだ評価されていません。