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

Linux Distribution Comparison

There are currently nearly 300 active Linux distributions, which makes choosing just one somewhat difficult, especially...
29/12/2020

[SSH] [Phần 1] Hướng dẫn tạo user sudo và cấu hình disable ssh đối với user root

Giới thiệu : Các lệnh sudo cung cấp 1 cơ chế để cấp các đặc quyền của quản trị viên, thông...
30/12/2020

Hướng dẫn fix lỗi erro 500 internal server

1. Lỗi HTTP Error 500 là gì? Do một sự cố nào đó trên máy chủ mà người dùng truy cập sẽ có thông...
28/12/2020
Bài Viết

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

Hướng Dẫn Chọn Dịch Vụ Thuê Địa Chỉ IPv4
10/03/2025

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024