in reply to Caching and inserting big number of records

Have a look at MySQL's page on the speed of insert statements. Specifically, using one insert statement with multiple value lines, and using the INSERT DELAYED syntax may be of use to you.

That said, if you can collect all of your data, then do a bulk insert, then using LOAD DATA INFILE with indexes turned off is supposed to be 20 times faster than using INSERT statements. This does require you to format your data in CSV, for which you can use Text::CSV_XS

Clint