webman使用thinkorm加cache的时候会报错

邹意

运行环境,php8.2:

截图

问题1:

使用thinkorm,字段content是存的数组序列化后的值,模型加了获取器的
获取器:
public function getContentAttr($value)
{
return $value ? unserialize($value) : [];
}

模型方法:

public function getConfig($id = null)
{
    $id = $id ?? request()->get('id') ;
    if(! $id) abort('参数错误');
    $data = $this->cache(true)->where('id',$id)->field('content')->find();
    return $data['content'] ?? [];
}

只有第一次调用会报错,如果把缓存去了就不会报错:
截图

问题2:

如果把模型方法改成这样:

public function getConfig($id = null)
{
    $id = $id ?? request()->get('id') ;
    if(! $id) abort('参数错误');
    //修改了这,把find改为value
    $data = $this->cache(true)->where('id',$id)->value('content');
    return $data ?? [];
}

这样问题就更大了,查询出来$data等于null,更别说缓存了

这两个问题我专门用thinkphp下测试了下,都不会出现

323 1 0
1个回答

JackDx

thinkcache.php设置调加:'serialize' => ['serialize', 'unserialize']试一试,好像是thinkcache兼容性问题,你PHP版本降低看看 如7.4

  • 邹意 2023-09-22

    第一个问题能解决,第二个问题依然存在

  • JackDx 2023-09-22

    应该thinkcache兼容性问题,我看thinkcache仓库有相同问题反馈,但是没有修复

  • yzh52521 2023-09-22

    自己维护一版吧

🔝