Yii Framework Forum: Cache is slow - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cache is slow Cache is slower than DB Result

#1 User is offline   kumarasathisha 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 06-December 17

Posted 06 December 2017 - 06:45 AM

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.

Thanks
0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2017 - 07:21 AM

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.
0

#3 User is offline   kumarasathisha 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 06-December 17

Posted 06 December 2017 - 07:29 AM

View Postalrazi, on 06 December 2017 - 07:21 AM, said:

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?

Thanks
0

#4 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2017 - 09:14 AM

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.
0

#5 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,410
  • Joined: 16-February 11
  • Location:Japan

Posted 06 December 2017 - 09:55 AM

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.
1

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,193
  • Joined: 17-January 09
  • Location:Russia

Posted 06 December 2017 - 10:06 AM

Redis would do as well.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
1

#7 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2017 - 02:55 PM

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.
1

#8 User is offline   kumarasathisha 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 06-December 17

Posted 07 December 2017 - 12:52 AM

View Postalrazi, on 06 December 2017 - 02:55 PM, said:

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.

Thanks
0

#9 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,481
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 07 December 2017 - 01:31 AM

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
http://www.yiiframew...ache-components

link to redis extension
http://www.yiiframew...edis-cache.html
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users