User Tools

Site Tools


memcached

Memcached

Return to Redis, Valkey (Redis's successor as a free software project), Conflict-free replicated data type, Memcached, Infinispan

Memcached

Memcached is a high-performance, distributed memory caching system. It's designed to speed up dynamic web applications by alleviating database load. It achieves this by storing frequently accessed data and objects in RAM, reducing the number of times an external data source, like a database, must be read.

Key Features

  • **In-Memory Key-Value Store:** Memcached stores data as key-value pairs in memory, offering incredibly fast access times.
  • **Distributed Architecture:** It's designed to work in a distributed environment, enabling horizontal scaling by adding more servers to the cluster.
  • **Simple API:** Memcached has a straightforward API that is available in most popular programming languages.
  • **LRU Eviction:** It employs a Least Recently Used (LRU) eviction policy to manage memory, automatically removing the least recently accessed data when memory is full.
  • **High Performance:** Memcached is optimized for speed, providing sub-millisecond response times for cached items.

Benefits

  • **Improved Performance:** By caching frequently accessed data in memory, Memcached significantly improves the performance of web applications, reducing the load on databases and other backend systems.
  • **Scalability:** Its distributed architecture allows it to handle large volumes of data and traffic by adding more servers to the cluster.
  • **Simplicity:** Memcached's straightforward API and easy setup make it simple to integrate into existing applications.
  • **Cost-Effectiveness:** Memcached reduces the need for expensive database hardware or additional resources by caching data in memory.

Code Examples

1. **Setting and Getting a Value (Python):**

```python import memcache

mc = memcache.Client(['127.0.0.1:11211'])

mc.set('key', 'value') # Store a key-value pair value = mc.get('key') # Retrieve the value print(value) # Output: 'value' ```

2. **Setting an Expiration Time (Python):**

```python import memcache

mc = memcache.Client(['127.0.0.1:11211'])

mc.set('key', 'value', time=3600) # Store a key-value pair with an expiration time of 1 hour ```

3. **Incrementing a Counter (Node.js):**

```javascript const Memcached = require('memcached');

const memcached = new Memcached('127.0.0.1:11211');

memcached.incr('counter', 1, (err, result) ⇒ {

   if (err) {
       console.error(err);
   } else {
       console.log(result); // Output: the new value of the counter
   }
}); ```

These examples illustrate how to use basic Memcached operations like setting, getting, and incrementing values using different client libraries.

Additional Resources


Snippet from Wikipedia: Memcached

Memcached (pronounced variously mem-cash-dee or mem-cashed) is a general-purpose distributed memory-caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached is free and open-source software, licensed under the Revised BSD license. Memcached runs on Unix-like operating systems (Linux and macOS) and on Microsoft Windows. It depends on the libevent library.

Memcached's APIs provide a very large hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order. Applications using Memcached typically layer requests and additions into RAM before falling back on a slower backing store, such as a database.

Memcached has no internal mechanism to track misses which may happen. However, some third party utilities provide this functionality.

Memcached was first developed by Brad Fitzpatrick for his website LiveJournal, on May 22, 2003. It was originally written in Perl, then later rewritten in C by Anatoly Vorobey, then employed by LiveJournal. Memcached is now used by many other systems, including YouTube, Reddit, Facebook, Pinterest, Twitter, Wikipedia, and Method Studios. Google App Engine, Google Cloud Platform, Microsoft Azure, IBM Bluemix and Amazon Web Services also offer a Memcached service through an API.

Snippet from Wikipedia: Redis

Redis (; Remote Dictionary Server) is a source-available, in-memory storage, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Because it holds all data in memory and because of its design, Redis offers low-latency reads and writes, making it particularly suitable for use cases that require a cache. Redis is the most popular NoSQL database, and one of the most popular databases overall. Redis is used in companies like Twitter, Airbnb, Tinder, Yahoo, Adobe, Hulu, Amazon and OpenAI.

Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.

The project was developed and maintained by Salvatore Sanfilippo, starting in 2009. From 2015 until 2020, he led a project core team sponsored by Redis Labs. Salvatore Sanfilippo left Redis as the maintainer in 2020. In 2021 Redis Labs dropped the Labs from its name and now is known simply as "Redis".

In 2018, some modules for Redis adopted the SSPL. In 2024, the main Redis code switched to dual-licensed under the Redis Source Available License v2 and the Server Side Public License v1.


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


memcached.txt · Last modified: 2024/08/28 15:46 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki