Now should i cache very rows from mysql?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sn4k3
Forum Commoner
Posts: 37
Joined: Tue Oct 16, 2007 3:51 pm

Now should i cache very rows from mysql?

Post 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
gooney0
Forum Commoner
Posts: 56
Joined: Fri Jan 21, 2011 1:40 pm
Location: Reston, VA

Re: Now should i cache very rows from mysql?

Post 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.
sn4k3
Forum Commoner
Posts: 37
Joined: Tue Oct 16, 2007 3:51 pm

Re: Now should i cache very rows from mysql?

Post 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
Post Reply