Tag: caching

Getting Started with Caching in PHP using memcached

Caching is used to store the data which are frequently used. The main advantage of caching is that it increases the performance of the site or an application by decreasing the load on to the server like database.

There are different caching methods to cache the data like caching content in file, memory or database. Memcached is one type of memory caching system. It is very useful when large number of data you want to cache.

It is distributed memory caching system. Memcached is key-value store for caching small chunks of data from result of database, API or page rendering. Basically it can cache anything if you can turn it into key => value. Memcached solves many problems related to large data caching.

Memcached is better because of the following reasons:

  1. It’s REALLY fast – Everything’s in memory, and it’s highly optimized for situations just like yours (and caching in general )
  2. It’s distributed – This means that if you have multiple web / app servers running, they can all access the same cache
  3. You can pool multiple servers for memcached – If you’ve got a few servers that are relatively underutilized (or several dedicated cache servers), you can pool them all together into one big cache
  4. It’s super-scalable (for the reasons mentioned prior)
  5. It’s got great PHP support – The PECL package for memcached was recently updated with a lot of new goodness
  6. You can even store your user sessions in memcached – just set it up in your php.ini file. This is much faster than storing sessions in databases, and allows your sessions to persist across multiple web hosts (if you’re in a load balanced situation). This will also give your site a bit of a performance boost as there’s no need to hit the file system / database for session info on every request.

What memcached does?

Read More