Bobcares

Memcached expiration time – Here is how we set it

by | Mar 2, 2020

Curious to know about Memcached expiration time?

Memcached is a caching system that helps to speed up websites by loading cached data.

The expiration time is the duration specified in seconds until which Memcached stores the data.

At Bobcares, users often approach us on queries regarding Memcached parameters, as a part of our Server Management Services.

Today, let’s see have a look at Memcached and a guide by our Support Engineers on the expiration time.

 

A quick look at Memcached

Memcached is an open-source, high-performance, distributed memory caching system. The purpose of this is to speed up dynamic web applications. Usually, it does this by reducing the database load.

Above all, the Memcached server is a big hash table suitable for websites with high database load.

Now let’s have a look at Memcached expiration time.

 

What is the expiration time in Memcached?

The expiration time is a parameter defined during data storage. Memcached allows users to use storage commands like the set, add, replace, append, prepend and CAS (Check-And-Set or Compare-And-Swap).

Let’s see what is expiration time by having a look at the set command. One way to connect to a Memcached server is by using telnet command. And the command usage is,

telnet <HOST> <PORT>

The default port for Memcached is 11211. Here, we connected to the Memcached server running on the localhost.

The Memcached add command adds a new value to a new or else an existing key. And the usage of this command is,

add key flags exptime bytes [noreply]

<value>

The other parameters in the command are,

  • key − This is the key name by which we can store and retrieve data from Memcached.
  • flags − This is a 32-bit unsigned integer. The server stores this flag with the data set by the user. Also, it returns the flag when we retrieve the data.
  • exptime − It is the expiration time in seconds.
  • bytes − The number of bytes in the data block. Usually, this is the length of the data that we store in Memcached.
  • noreply – This optional parameter informs the server not to send any reply.
  • <value> − It is the data we want to store. Always enter the data on a new line after executing the set command.

A sample output of adding a new key using add command appears as,

Memcached expiration time.

Here the name of the key is key itself, the flag is 0, the expiration time is 900 seconds, and bytes is 9. And we added value ‘memcached‘. After using the get command we obtained the added values.

Now let’s have a closer look at exptime or expiration time.

 

A detailed look at exptime

The expiration time in Memcached is in seconds. For instance, the default value is 10800 seconds. But, it can have a maximum value of 2592000 seconds that is, 30 days.

A value greater than 2592000 is a Unix time in Memcached. Because Memcached counts Unix time from the number of seconds since January 1, 1970.

Similarly, we can also have no automatic expiration by specifying expiration time as zero. Memcached has a lazy caching. That is, it deletes values only when requested, or during a new entry when the cache is full.

More specifically, Memcached deletes items before there expiration time due to the unavailability of memory.

 

Manually clearing cache

Even though Memcached speeds up a website by loading cache, this has a drawback. Memcached still loads the cache after the website update. This is not desirable.

So, there is a need to clear the cache before the expiration time. And this is possible in Memcached. For this, our Support Engineers use the command,

flush_all

This removes all the stored cache.

 

[Still, having trouble in setting up the Memcached server? – We can help.]

 

Conclusion

So far, we saw a brief guide on Memcached expiration time. This parameter determines the duration of how long Memcached stores data. We also saw how our Support Engineers set the expiration time for a new key.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF