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

PRIVATE PROXY LÀ GÌ? MUA PRIVATE PROXY Ở ĐÂU?

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...
13/11/2022

Working with Raspberry Pi 3 GPIO with Python

Raspberry Pi is a single board computer that runs on Linux. It is mainly used for IoT (Internet of Things) projects. As...
29/12/2020

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT

Proxy Việt Nam hiện đang phục vụ tốt nhu cầu sử dụng, kinh doanh, truy cập internet của người dùng....
13/05/2024
Bài Viết

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

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024