A lease is an ID that Memcached hands out with every cache miss for a key, so that a late set carrying an old value fails.
Memcached starts with zero data. Two web servers miss on the same key, A:
- The slow web server reads A from the database and gets 10.
- The fast web server sets A to 20 in the database.
- The fast web server reads A, gets 20 and sets it in the cache.
- The slow web server sets A to 10 in the cache.
The cache holds 10 and the database holds 20.
With leases, the fast web server picks up a new lease ID. The slow web server finds its lease ID is not valid, reads the value again and sets it. A lease ID is similar to a version number and to optimistic locking.
Availability is the higher priority, so there is no strong consistency. Read after write is not strict. In rare cases a read does not show the reader's own update.