GeneaLabs / laravel-model-caching没有通过急切加载来缓存我的雄辩查询

I came across this library https://github.com/GeneaLabs/laravel-model-caching and trying to use it in a project of mine.

Firstly, I've added the following line to my .env:

MODEL_CACHE_STORE=file

I am using file cache store to test, in production I will use redis.

Then I've created app/CacheableModel.php with the following:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;

abstract class CacheableModel extends Model
{
    use Cachable;
}

and then I've updated all my models (except for app/User.php) like this example:

<?php

namespace App;

class Company extends CacheableModel
{
    ...
}

and I tested it using a test route like this:

Route::get('test', function() {

    $testUser = \App\User::where('email', 'test@domain.com')
        ->with('company.users', 'company.subscription')
        ->first();

    dump($testUser->toArray());

});

When I visit test route, I can see the data loaded and dumped. If I refresh the page, it doesn't seem to be caching to be caching the above query.

I verified that it's not caching my eloquent queries by looking at the query log (using laravel telescope) as well as looking at storage/framework/cache/data - it's empty.

Any ideas what might be wrong?

Is this not caching because app/User.php model doesn't use the CacheableModel base class and the test query starts from the user model?

duanbarong4321
duanbarong4321 请尝试使用除用户型号以外的其他型号。希望它能奏效!
一年多之前 回复
dongliang1865
dongliang1865 我觉得你用过Cachable;没有雄辩的缓存。尝试使用github.com/GeneaLabs/laravel-model-caching中的演示代码,然后进行测试。也许你发现了什么问题!另外,请从以下文档中读取以下内容:例外:用户模型github.com/GeneaLabs/laravel-model-caching#exception-user-model
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问