Yii Framework Forum: Best Approach To Keep Records In Memory - Yii Framework Forum

Jump to content

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

Best Approach To Keep Records In Memory How Read All Records To Stop Query Same Records Rate Topic: -----

#1 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 23 May 2013 - 04:06 PM

Hi,

I Have News Site Which Loads News From News Table ,
I have 5,6 widgets which loads records from same table but with some change in query Criteria

I guss if i read all records in db for current day and keep theme in global scope so for each widgets just filter Array or go for Loop in Array

Is There Better Approach ? Any Ideas ?

if i separate query for each widget i should query 5 time in pagerequest and for 1000 user its ==> 5*1000=5000 but with array its just 1000 query .
Another Problem May Happen is Memory Overload for high quantity requests
0

#2 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 24 May 2013 - 07:11 AM

After 24 hours No Answer Recevied?

please tell your solution about question

Another solution i have though is Cache Those Queries Which are repetetive
0

#3 User is offline   Ivo Pereira 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 29-July 12

Posted 24 May 2013 - 09:39 AM

Have you tried APC cache?
0

#4 User is offline   softark 

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

Posted 24 May 2013 - 10:10 AM

Hi Mohammad,

Yii supports various range of caching ... from the data caching or the query caching at the bottom layer to the page caching on the top.

http://www.yiiframew...aching.overview

You can cache the content of each widget by query caching or fragment caching. And also the page caching will do a great job, if the news are not so frequently updated compared to the page views.
1

#5 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 25 May 2013 - 02:01 AM

View Postsoftark, on 24 May 2013 - 10:10 AM, said:

Hi Mohammad,

Yii supports various range of caching ... from the data caching or the query caching at the bottom layer to the page caching on the top.

http://www.yiiframew...aching.overview

You can cache the content of each widget by query caching or fragment caching. And also the page caching will do a great job, if the news are not so frequently updated compared to the page views.


Thank You , For Replies

I Guess Caching is The Best Method , But is It possible to cache a query but some where change one params? or i should cache again for new changes?
0

#6 User is offline   softark 

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

Posted 25 May 2013 - 04:42 AM

The query caching uses SQL string (or precisely saying the hash of it) as the key to the entry. For example, the results of the following 2 SQLs will be cached into the separated entries.
1. SELECT * from table where some_field like '%yii%'
2. SELECT * from table where some_field like '%php%'

When 2 of your widgets uses exactly the same SQL, then they will share the same cache entry. But if there are any difference between the 2 SQLs, no matter how small the difference might be, they will be cached as the different entries.

Well, I don't get precisely what you mean by "Array" in your first post, but I don't think it's a good idea to cache some range of db records for generic purpose and loop through it to get each result sets for individual widgets.
1

#7 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 26 May 2013 - 01:58 AM

thank you for reply

i ask you make post in wiki for best caching techniques to make performance higher and suggest where to fragment caching , query caching and all type of caching
0

#8 User is offline   Boaz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 367
  • Joined: 23-January 11

Posted 27 May 2013 - 01:21 AM

I also advise you to carefully check your 'cache dependency' conditions, and/or set ones. Not thinking in advance on those issues can lead to hard to find bugs. It all depends on your exact requirements, BTW.
Information on 'cache dependency' and expiration setting can be found in the link given above by softark to the official documentation.
Therapeutic PHP sessions My LinkedIn Profile
0

#9 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 28 May 2013 - 02:35 AM

Another question To Ask Is
If i cache query and forexample query is "select * from news order by date DESC";

if data was added to table is caching work or read from db or it doesn't negative effect on cache ???
0

#10 User is offline   softark 

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

Posted 28 May 2013 - 04:49 AM

If you haven't defined any dependency, then cache will remain the same ... the outdated content will continue to be served from the cache. So we usually define some dependency to invalidate the cache entry if something has changed in the relevant tables.

Just as Boaz said, the settings of expiration and dependency are the critical path. Please refer to the official documentation for details.
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