Page 1 of 1

Now should i cache very rows from mysql?

Posted: Fri Oct 14, 2011 6:12 pm
by sn4k3
Hi, heres my table:

Code: Select all

CREATE TABLE `stats_css` (
 `id` int(10) unsigned NOT NULL,
 `reliability` tinyint(3) unsigned NOT NULL DEFAULT '100',
 `ragequit` tinyint(3) unsigned NOT NULL DEFAULT '0',
 `played` int(10) unsigned NOT NULL DEFAULT '0',
 `won` int(10) unsigned NOT NULL DEFAULT '0',
 `drawn` int(10) unsigned NOT NULL DEFAULT '0',
 `lost` int(10) unsigned NOT NULL DEFAULT '0',
 `assists` int(10) unsigned NOT NULL DEFAULT '0',
 `kills` int(10) unsigned NOT NULL DEFAULT '0',
 `deaths` int(10) unsigned NOT NULL DEFAULT '0',
 `roundswon` int(10) unsigned NOT NULL DEFAULT '0',
 `roundsdrawn` int(10) unsigned NOT NULL DEFAULT '0',
 `roundslost` int(10) unsigned NOT NULL DEFAULT '0',
 `headshots` int(10) unsigned NOT NULL DEFAULT '0',
 `damagegiven` int(10) unsigned NOT NULL DEFAULT '0',
 `damagerecived` int(10) unsigned NOT NULL DEFAULT '0',
 `bombsdefused` int(10) unsigned NOT NULL DEFAULT '0',
 `bombsplanted` int(10) unsigned NOT NULL DEFAULT '0',
 `1man_played` int(10) unsigned NOT NULL DEFAULT '0',
 `1man_won` int(10) unsigned NOT NULL DEFAULT '0',
 `2man_played` int(10) unsigned NOT NULL DEFAULT '0',
 `2man_won` int(10) unsigned NOT NULL DEFAULT '0',
 `3man_played` int(10) unsigned NOT NULL DEFAULT '0',
 `3man_won` int(10) unsigned NOT NULL DEFAULT '0',
 `4man_played` int(10) unsigned NOT NULL DEFAULT '0',
 `4man_won` int(10) unsigned NOT NULL DEFAULT '0',
 `5man_played` int(10) unsigned NOT NULL DEFAULT '0',
 `5man_won` int(10) unsigned NOT NULL DEFAULT '0',
 `maps` text COLLATE utf8_unicode_ci,
 PRIMARY KEY (`id`),
 CONSTRAINT `stats_css_ibfk_1` FOREIGN KEY (`id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
id refers to user, and every user have one row here
so stats should be selected very offten, since self user and other users can check stats in pre lobby
so i would to cache to prevent MySQL acesses, and renew cache when player finish a game

how should i cache this?
set a cache name per user like: "user1", "user2"?

another question: php save cache into files, and only put in memory when we access to it or its always on memory?

NOTE: Using APC

thanks

Re: Now should i cache very rows from mysql?

Posted: Sat Oct 15, 2011 1:22 am
by gooney0
I'm not sure I understand your question. Here is how I'd do this:

When user logs in check $_SESSION for stats. If unset, query the table for stats. Save the stats into $_SESSION as an array.

If the stats change, update the database and update the $_SESSION array.


With this method you only need to SELECT once per session + once per change.

Re: Now should i cache very rows from mysql?

Posted: Sat Oct 15, 2011 9:52 am
by sn4k3
yes, but my question is about cache with APC or other cache system, because stats is not only avaliable to owner, but to every one user can see stats of each others...

so my question is how to do that, since there are very rows to cache