Cache is slow

Hey There,

Im using Yii2 Query Cache in my application. initially i have created 2 functions called list() and cache(), im getting records from Database table in list() and getting records from cache in cache(). in my local machine cache() loads values faster than list() as expected but its reversed in my server so im stuck. can any one pl suggest me go ahead.


what storage are you using for cache if your using file adapter, I suggest you should swap out your file adapter with redis or memcache adapter.

Yes Im using File… May i know its not working in my server?


reason why your cache is slower then your list function is likely because list is held memory and where as your cache is on the disk, disk is much slower than memory as I said above use redis or memcached adapter if you want faster cache instead of file based adapter.

I agree with @alrazi.

Usually a relational database engine itself has some built-in cache mechanism. So caching the db-query results in a relatively slower cache medium (e.g. file and ordinary db) may decrease the performance despite your intention.

I would use a memory-based cache like memcache or apcu for it.

Redis would do as well.

redis is better option IMO, company I am helping at the moment, I sugggested we switch from memcached to redis now we utilize it for cache as well as other things like we power the activity stream with redis our geospatial data is also in redis.

Thanks All For The Support,

Actually im new to Yii and Caching mechanism as well… so can any one provide me necessary example for redis cache to solve it.


here is link to the docs you have to swap out your file adapter with redis and configure it, the api is same thats the beauty of yii.

link to cache guides

link to redis extension