Laravel Cache: Multiple Redis drivers hit the same key and it takes time

443 Views Asked by At

Cache . Multiple Redis drivers hit the same key and it takes time

As you can see in the image here, I am calling the same key multiple times in the same request.

In each case, it takes 0.16 or even 0.26 milliseconds. As a result, we will see that even if the caches on the same key are many, it will take quite some time

So I was trying something, if I could override the method get() of Illuminate\Cache\Repository as in this: Question

I will be able to put any keys that already have been hitted in a php array in a custom class CacheHandler, for example:

namespace App\Lib\CacheHandler;

class CacheHandler
{
    public $stats = [];

    /**
     * @param $key
     * @param $value
     */
    public function setStats($key, $value): void
    {
        $this->stats[$key] = $value;
    }

    /**
     * @param $key
     * @return mixed|null
     */
    public function getStats($key)
    {
        //return $this->stats[$key];
        //return $this->stats[$key] ?? null; // can't make `nothingHere` as null  because  stats[$key] = null
        return $this->stats[$key] ?? 'nothingHere'; // can't make `nothingHere` as null  because  stats[$key] = null
    }
}

I would appreciate any idea, if anyone has one, please share it.

0

There are 0 best solutions below