How To Install Memcached on Ubuntu

28/12/2020
With the increase in traffic, it is not unusual that websites start getting slow and show degraded performance. This performance effect is due to the fact that the database used in the backend cannot cope up or scale based on the traffic the website has started receiving. One of the ways to prevent this from happening is to use a good caching system like Memcached.

What is Memcached

According to the official Memcached website:

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. Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

Getting Started

We can get started with Memcached with just a few set of commands. Once the installation has completed, we will also test to verify it has been installed correctly and is running.

Installation

We will run the following apt-get based command to install Memcached on our Ubuntu 16.04 machine:

sudo apt-get install memcached

Here is what we get back with this command:

Starting Memcached

It is easy to start Memcached as a daemon server. By default, Memcached runs on port 11211. We can start using the command:

memcached -d

We can even run multiple instances of Memcached or run it on a different port using the same command:

memcached -p 11111 -U 11111 -d

These two commands produce no output:

Storing Data in Memcached

Now that our Memcached instance has started on port 11211, we can first verify that it is running:

Now, we’re ready to store and get data from memcached. Use the following format while storing data into Memcached:

set KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES

To get a key, use this format:

get KEY

To replace key-value, use trhe replace command as:

replace KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES

Finally, to remove key from Memcached, use the delete command:

delete KEY

Let’s try an example:

Conclusion

In this lesson, we looked at how we can install and start using Memcached which is an excellent Object caching system which stores data in the memory itself so that subsequent calls can be made faster to the database.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Upgrade To Latest SQLite3 on CentOS7

How to Upgrade to the Latest SQLite3 on CentOS7 SQLite 3 is a lightweight simple file based database system. It is used...
28/12/2020

Linux File Compression Options and Comparison

Compression, in general, is a useful method that is essentially encoding information using less data than the original...
29/12/2020

Lý Do Mua Proxy HTTP & SOCKS5 giá rẻ tại Onet.com.vn

DỊCH VỤ THUÊ PROXY PRIVATE DEDICATED ONET IDC cung cấp dịch vụ IP Proxy Private giúp quý khách sử dụng...
09/11/2022
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn fake ip bằng phần mềm SStap
10/06/2025

VPS treo game là gì? Thuê VPS treo game giá rẻ, không lo giật lag
02/06/2025

 BitBrowser – Best Anti-Detect Browser!
26/05/2025

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025