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条回答

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条