No, by default, Memcached is not persistent. It means that the data in Memcached does not persist after a restart or shutdown of the Memcached server. When the server restarts, it starts with an empty cache.
However, Memcached provides an option to store data persistently using the -m
flag when starting the Memcached server.
The -m
flag specifies the amount of memory to allocate for the cache, but it also takes an optional argument M
, which enables persistence. Here's an example command to start a Memcached server with persistence enabled:
memcached -m 512M -P /tmp/memcached.pid -d -u memcached -l 127.0.0.1 -p 11211 -P /tmp/memcached.pid -I 1m -vvv -o pslab_enabled=true
In this example, the -m
flag is set to 512M
, and the M
flag is included to enable persistence. The -P
flag specifies the path where the Memcached server stores its process ID. -d
runs the server as a daemon process, enabling it to run in the background. The -u
flag sets the user under which the daemon process will run. The -l
flag specifies the IP address on which the server listens for incoming connections. The -p
flag specifies the port number on which the server listens for incoming connections. The -I
flag sets the maximum size of each item that can be stored in the cache. The -vvv
flag increases the verbosity level of the server logs. The -o
flag enables additional options; in this case, pslab_enabled
is set to true
.
With persistence enabled, Memcached writes data to disk when the cache is full or when the server shuts down. The data is stored in a file called memcached.dat
in the current working directory. When the Memcached server starts up, it loads the data from this file into memory.
It's important to note that enabling persistence can affect performance since writing data to disk is slower than writing to memory. Additionally, Memcached does not provide any guarantees about the durability of the data. Data loss can occur if the server crashes or loses power before it can write data to disk. Therefore, it's recommended to use Memcached with persistence only for caching non-critical data.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.