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

Thuê mua proxy Tiktok tăng doanh thu, hiệu quả cao

Tiktok đang là một trong những nền tảng mạng xã hội được yêu thích và có số lượng tài khoản...
11/05/2024

Make Raspberry Pi Thin Client

A thin client is a low power computer that can connect to other powerful computers remotely usually via VNC or RDP protocol...
29/12/2020

Hướng dẫn thêm tính năng chủ trì (host) trên Jitsi

Sau khi cài đặt Jitsi, mọi người đều có thể vào trang web của chúng ta để tạo phòng họp. Để...
30/12/2020
Bài Viết

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

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

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ảo Hóa & Cloud
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ceph
04/04/2025