Storing frequently accessed data in a file rather than MySQL Storing frequently accessed data in a file rather than MySQL database database

Storing frequently accessed data in a file rather than MySQL


You have to remember that reading a table from a database on a powerful server and on a fast connection is likely to be faster than reading it from disk on your local machine. The database will cache the entirety of these small, regularly accessed tables in memory.

By implementing the same functionality yourself in the file system, there is only a small possible speed up, but a huge chance to mess it up and make it slower.

It's probably best to stick with using the database.


  1. Optimize your queries (using mysql slow query log) and EXPLAIN function.

  2. If tables are really rarely written to you can use native MySQL caching. You have nothing to change in you code, just enable mysql caching in my.conf.

  3. Try out using template engine like Smarty (smarty.net). It has it's own caching system that works pretty well and will REALLY reduce server load.

  4. You can also use Memcache, but it is really worth using only with really high load websites. (I think that Smarty will be enough.)


Databases are much better at handling large data volumes than the native file system.

Don't worry about optimizing your site to reduce server load, until you actually have a server load problem. :-)