What’s memcached and why do you need to use it

07.02.2019 886 0

Having a properly working website or app can make a big difference in your overall online presence. People will rarely wait for your site or service to load and caching is a vital part of optimizing your performance. And out of many choices memcached often is one of the most used solutions.

The official description of memached sounds a bit long and confusing for some: “Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.”

So, what does all of this actually mean?

Caching is an important part of any online service, site, app and so on. It allows for better use of resources and lowers the user latency. It can also lower the amount of data and traffic and reduce the unneeded requests to the server.

Caching allows assets to be stored in the server’s RAM or even the user’s device which helps out with repeated objects, images and so on. This way the browser for example doesn’t have to download the same logo image from the server for each new page click. Instead, it can just use the one in the cache and download only the different/new content.

As a result, caching becomes a very important part of the overall performance of the site. And it’s something which these days is basically mandatory for proper search engine optimization (SEO).

Benefits of Memcached

Memcached is a method of caching which over the years has enjoyed a lot of popularity among webmasters. It works well and it’s relatively easy to set up. In fact, most web hosts have already set it up and you can basically turn it on with a couple of clicks in the cpanel. WordPress also supports it with various plugins, as do most other ready-made web platforms for blogs, stores and so on.

Memcached sets a key, expiration time, raw data and optional flags to each item. Upon request, the system checks the expiration date of the item and it is valid, it gives the item to the client. If it isn’t – it updates it from the database. This way the client gets the most up-to-date version of the item. It also automatically replaces expired items with new ones and keeps the more recently requested items in the memory. Admins can configure these time periods and other details to their preferences.

Memcached is a good choice for small and static data, i.e. websites. It supports only strings, so if you have a lot of read-only data, memcached is a good option.

Another benefit is the fact that Memcached is multithreaded and you can scale it up quite easily. If all clients use the same hashing algorithm to determine servers, then clients can read each other’s cached data. Memcached servers, though, don’t share data between each other, so you need to keep that in mind when building your setup.

You can also set up Memcached on Linux, Windows and macOS servers. It’s cross-platform and easy to maintain.

Obviously, Memcached is not all-powerful and can’t solve all problems. So, when writing your code, or creating a website, make sure it’s well optimized so it will run properly without Memcached.

Memcached won’t be able to make a poorly written site perform well. It can make a well working site handle requests and information even better, though.

Leave a Reply

Your email address will not be published.