Use Memcached to improve database performance

To make an existing web shop with many products and options faster and able to handle more users at the same time, you’ll need to cache the most-used data and store it in such a way that minimal resourses are necessary to deliver the data to the application or to the user.
The most intensively used resourse for a common php/mysql web shop is usually the database storing the product data. The database is constantly queried to provide the application with actual price, stock and product data for every page the customers visit. For every visitor the website is re-created using the most actual information from the database and this could slow down your site as visitor numbers increase. Most web shops do not update their product database every 10 minutes so it is not necessary to query the database every time a visitor enters a product page.

Introducing Memcached

Memcached is a free & open source, high-performance, distributed memory object caching system. It is generic in nature but because it is a key value store it is especially useful for speeding up dynamic web applications by alleviating database load.
Memcached can be implemented between your php and database requests and stores the result of your database query’s in the RAM for a specified time. In the configuration you can allocate the RAM that Memcached can use. If implemented the right way, this could decrease your database traffic enormously (In some cases by more than 95%) and speed up your web shop.

The proper way to implement memcached:
  • A result hash from the select query will first be requested at the Memcache daemon. If there is no result hash cached, the query will be executed against the database. The subsequent result will be delivered to the application but the result hash will again be stored in Memcached for a specified time.
  • The next select query of the same form will find a valid result hash in the Memcached and the result will be delivered directly from RAM without querying the database.

  • Write your code in such a way that it can function without Memcached. Then your cache is truly transparent.
  • Know what to cache and when to cache. Query’s in the admin interface are not a good candidate while landing page query’s often are because of the amount of visitors they process.


Tutorials and installation info:



General FAQ

Show all FAQs

OpenStack FAQ

Show all FAQs


Show all FAQs