Javatpoint Logo
Javatpoint Logo
Memcached Interview Questions

Memcached Interview Questions

A list of top frequently asked Memcached interview questions and answers are given below.

1) What is Memcached?

Memcached is a general-purpose free and open source, high performance, distributed memory object caching system. It is used to speed up database-driven websites by caching data and objects in RAM.

In simple words, you can say that Memcached is a component which stores data temporally for 1hour/ 6 hour/ 12 hours/ 1 day, etc. and you can integrate this component with your applications to increase their performance.


2) In which language Memcached is written and who is the author?

Memcached is written in "C language". It was developed by Brad Fitzpatrick in 2003. Initially, it is developed for LiveJournal, but now it is used by Wikipedia, Twitter, Facebook, Flickr, Netlog, YouTube, etc.


3) How Memcached works?

See the following steps to understand how Memcached works:

  • Memcached first tries to get the detail of the user, and the browser sends the request to the application.
  • An application calls the Memcached for a particular user.
  • If Result found in Memcached, Return the result from Memcached.
  • If Result Not found in Memcached, Application sends the request to the database and save the result in Memcached.
  • Each Memcached have one unique key.
  • Get/Set the data work on behalf of the key.
  • You can also delete one or more keys.
  • You can also assign tags to one/more keys.

4) When was the first version of Memcached launched?

The first version of Memcached was launched on May 22, 2003.


5) What is the usage of Memcached? In which types of websites, it is generally used?

Memcached is used to increase the speed of dynamic database driven websites. It caches data and objects in RAM to reduce the execution time.

It is generally used:

  • In social networking sites for profile caching.
  • For content aggregation i.e. HTML/Page caching.
  • In E-commerce websites for Session and HTML caching.
  • In location-based services for database query scaling.
  • In gaming and entertainment services for session caching.
  • It can also be used to track cookie/ profile for ad targeting.

6) What is the best usage of Memcached?

Best usage of Memcached:

  • It is easy to install in Windows as well as in the UNIX operating system.
  • It provides API integration for all the major languages like Java, PHP, C/C++, Python, Ruby, Perl, etc.
  • It enhances the performance of web application by caching.
  • It reduces the burden of the database server.
  • It facilitates you to delete one or more values.
  • It facilitates you to update the values of keys.

7) What are the drawbacks/ limitations of Memcached?

A list of the limitations or drawbacks of Memcached:

  • Memcached cannot store data persistently and permanently.
  • Memcached is not a database. It stores only temporary data.
  • Memcached cannot cache large objects.
  • Memcached is not application specific.
  • Memcached is not fault-tolerant or highly available.

8) In which conditions cache cannot retain the stored information?

The cache cannot retain the stored information in following conditions:

  • When the allocated memory for the cache is exhausted.
  • When an item from the cache is deleted.
  • When an individual item in the cache is expired.

9) What is the difference between Memcache and Memcached?

Difference between Memcache and Memcached:

Table:

Memcache Memcached
Memcache module provides handy procedural and object-oriented interface to Memcached. Memcached is a high-performance, distributed memory object caching system.
Memcache is an extension that allows you to work through handy object-oriented (OOP's) and procedural interfaces. Memcached is an extension that uses the libMemcached library to provide API for communicating with Memcached servers.
The Memcache module provides a session handler (Memcache). The Memcached provides a session handler (Memcached).
It is designed to reduce database load in dynamic web applications. It is used to increase the dynamic web applications by reducing database load. It is the latest API.

10) Can we share a single instance of Memcache between multiple projects?

Yes, we can share a single instance of Memcache between multiple projects because being a memory storage space, Memcache can be run on one or more servers. In Memcache, you can also configure your client to speak to a particular set of instances.

We can also run two different Memcache processes on the same host being completely independent and without any interference. If you partition your data, it is important to know from which instance to get the data from or to put into.


11) Explain the differences between SAP HANA and Memcached?

SAP HANA is an in-memory RDBMS and mostly used for accelerating SAP applications while Memcached is a key/value caching system and used for accessing both RDBMS and NoSQL databases.


12) How to connect Memcached server with telnet command?

By using telnet hostname portNumber command, you can connect Memcached server with telnet command.

Syntax

Example

The given example shows that how to connect to a Memcached server and execute a simple set and get command. Let's assume that the server of Memcached is running on host 127.0.0.1 and port 11211.


13) How to get the value of key?

By using the get command, you can get the value of the key.

Syntax

Example

In the given example, we use javatpoint as the key and store Memcached in it with an expiration time of 900 seconds.


14) How to set the value of key?

By using set command, you can set the value of the key.

Syntax

Example

In the given example, we use javatpoint as the key and set value Memcached in it with an expiration time of 900 seconds.


15) How to add value in the key?

By using add command, you can add value in the key.

Syntax

Example

In the given example, we use "key" as the key and add the value Memcached in it with 900 seconds expiration time.


16) How to replace the value of the key?

By using replace command, you can replace the value of the key.

Syntax

Example

In the given example, we use "key" as the key and add the value Memcached in it with 900 seconds expiration time. After this, the same key is replaced with the "redis".


17) How to append the value of the key?

By using append command, you can append the value of the key.

Syntax

Example

In the given example, we are trying to add some data in a key that does not exist. Hence, NOT_STORED is returned by Memcached. After this, we set one key and append data into it.


18) How to prepend value of key?

By using prepend command, you can prepend value of the key.

Syntax

Example

In the given example, we are trying to add some data in a key that does not exist. Hence, NOT_STORED is returned by Memcached. After this, we set one key and prepend data into it.


19) How to delete the key?

By using delete command, you can delete the key.

Syntax

Example

In the given example, we use javatpoint as a key and add the value Memcached in it with 900 seconds expiration time. After this, it deletes the stored key.


20) How to show the stats?

By using stats command, you can show the stats.

Syntax

Example


21) How to get the versions?

By using Version command, you can get the versions.


22) How to close the connection?

By using the Quit command, you can close the connection.


23) How would you update Memcached when data changes?

There are two methods to update Memchached when data changes:

  • By clearing the cache proactively: You can update Memcached by clearing the cache while insertion or updation is made.
  • By resetting the cache: It is slightly similar to the first method, but it doesn't delete the keys and wait for the next request for the data to refresh the cache, it resets the values after the insert or update.

24) What is Dogpile effect? How can you prevent this effect?

If the cache expires, and websites are hit by multiple requests made by the client at the same time, this effect is known as Dogpile effect.

This effect can be prevented by using a semaphore lock. In this system when value expires, the first process acquires the lock and starts generating new value.


25) What happens to the data stored in Memcached when server accidentally gets shut down?

In Memcached, data is not permanently stored. It is not a durable data so, if the server is shut down or restarted, all the data stored in Memcached will be deleted.


26) If you have multiple Memcache servers and one of the Memcache servers fails which has your data, will it ever try to get key data from that one failed server?

The data in the failed server won't get removed, but there is a provision for auto-failure, which can be configured for multiple nodes. Fail-over can be triggered during any socket or Memcached server level errors and not during normal client errors like adding an existing key, etc.


27) How can you minimize the Memcached server outages?

Following are the methods to minimize the Memcached server outage:

  • When one instance fails, several of them go down, this situation will put larger load on the database server when the client reloaded the lost data. To avoid this, you should write your code to minimize cache stampedes, and it will leave a comparatively less impact.
  • You can bring up an instance of Memcached on a new machine using the lost machines IP address.
  • The Code is another option to minimize server outages as it gives you the liberty to change the Memcached server list with minimal work.
  • Setting timeout value is another option that some Memcached clients implement for Memcached server outage. When your Memcached server goes down, the client will keep trying to send a request till the time-out limit is reached.


You may also like:


Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA