Laravel 5.6 Cache :: rememberForever不使用变量密钥缓存数据

问题描述 投票:0回答:1

使用Laravel 5.6使用memcached驱动程序缓存查询。当我在密钥名称中使用变量时,结果永远不会被缓存,并且它使用数据库调用,但同一查询使用'test'作为密钥名称。我错过了什么?

不起作用......

/**
 * Get one id
 * @param $id
 * @return \Illuminate\Database\Eloquent\Model|null|object|static
 */
public function get($id)
{
    return Cache::rememberForever('species-' . $id, function () use ($id) {
        return AnimalSpecies::where('id', $id)->with('subspecies', 'morphs', 'combos', 'localities')->first();
    });
}

工作......

/**
 * Get one id
 * @param $id
 * @return \Illuminate\Database\Eloquent\Model|null|object|static
 */
public function get($id)
{
    return Cache::rememberForever('test', function () use ($id) {
        return AnimalSpecies::where('id', $id)->with('subspecies', 'morphs', 'combos', 'localities')->first();
    });
}
php laravel-5 memcached
1个回答
0
投票

我的问题是通过$id传递了一个不正确的变量,它是一个带有空格的字符串,这不是一个允许的字符。一旦我通过正确的数字$id缓存工作完美。

© www.soinside.com 2019 - 2024. All rights reserved.