Question

In Laravel, is anything built into the framework which can count redis (Cache) and database calls per one request lifecycle?

I want to see how many cache vs DB fetches are made in various API routes.

Thank you in advance.

Was it helpful?

Solution

You can get the database query log quite easily as each query is logged automatically:

$queries = DB::getQueryLog();

There's nothing built in that will show you the number of cache calls that were made. That said, it wouldn't be too hard to override the cache repository to have it log all cache calls.

OTHER TIPS

There is not an actual count of items. Redis is a caching system so you are storing items inside the caching system instead of making a DB call.

Furthermore all Laravel provides is a quick interface and service towards Predis which is a wrapper for Redis.

This is the lib: https://github.com/illuminate/redis

and the document associated to it: http://laravel.com/docs/redis

if you need counting, consider simply inserting a specific value inside the cache and use the increment functions to increase your count and then do a get to retrieve back the value quickly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top