lundi 19 février 2018

Laravel 5.6 Cache::rememberForever not caching data with variable key

Using Laravel 5.6 to cache queries using the memcached driver. When I use a variable in the key name, the results are never cached and it uses the database call but the same query works with 'test' as the key name. What am I missing?

Does not work...

/**
 * 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();
    });
}

Does work...

/**
 * 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();
    });
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire