I'm implementing a memory cache for a table that looks like this (simplified):
Item1 (integer), Item2 (integer), cnt (Integer)
The original table includes millions of pairs like this. and it updates rapidly.
To make it all more efficient I want to write new pairs to an identical memory table and update the real table on disk periodically by cron.
The cron should do the following: for each pair if there is similar pair in the non-memory table increase the count by the count from the memory table. If no such pair exist create it with count from the memory table.
How can I make the flush (from memory table to real table) most efficient?
Notes: The environment is Mysql 5.0.45 PHP 5.2.6 CentOS