I have two methods one of them queries the database and another one retrieves data from Redis cache.
public function aaa()
{
for ($i = 0; $i < 1000; $i++) {
$gl = DB::connection('webhesab')->table('gl_trans')
->where('memo_', 'LIKE', '%شعبه%')
->orWhere('account', '=', 111001)
->where('dimension2_id', '<>', 1)
->orWhere('person_id', '=', 0)
->where('dimension2_id', '<>', 1)
->orWhere('type_no', '<>', 50)
->limit(10)
->get();
}
}
public function bbb()
{
for ($i = 0; $i < 1000; $i++) {
$gl = cache()->get('gl_trans');
}
}
value of the cached object is exactly like query value.
But cache is so much slower than database query. roughly aaa
longs 300 ms and bbb
longs 1900 ms. Why? What is the problem?
you should post cache() implementation. without those, people can't help you explain why it's slow
there are some other points
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.