dongye3917 2019-02-28 01:54
浏览 142

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?