Memcache Binary Protocol: Extensions for UDP Six Apart, Ltd.
548 4th Street San Francisco CA 94107 USA aaron@serendipity.palo-alto.ca.us
Applications memcache memcached cache udp This memo explains extensions to the memcache binary protocol for use in a UDP environment. Memcache is a high performance key-value cache. It is intentionally a dumb cache, optimized for speed only. Applications using memcache do not rely on it for data -- a persistent database with guaranteed reliability is strongly recommended -- but applications can run much faster when cached data is available in memcache.
Memcache is a high performance key-value cache. It is intentionally a dumb cache, optimized for speed only. Applications using memcache do not rely on it for data -- a persistent database with guaranteed reliability is strongly recommended -- but applications can run much faster when cached data is available in memcache. Sites may find that, due to their network architecture or application usage patterns, the stateless protocol better suits their needs. This document provides extensions and descriptions of use of the memcache protocol in a UDP environment. It is a goal of this document to provide sufficient information in each UDP packet as to avoid any requirement for statefulness on the part of the server nor significant caching of outstanding packets on the part of the client.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in .
The magic bytes remains the same as in .
Additional status values: Value is larger than a single response packet
Additional opcode values: Get Range Set Range
There are no new data types in this extension.
This section extends the behavior of the Get and GetQ commands as described in . When a Get or GetQ request is made via UDP, and the value of the key for which the request was made is larger than can be placed into a single UDP packet (noting that the protocol header must also be counted), a Get Range response packet MUST be sent instead of the Get response packet. In this instance: The Status field of the response header MUST be 0x0004. The Offset field of the GetR response extras MUST be 0. The Length field of the GetR response extras, and the data contained in the Value field of the packet, SHOULD be the maximum allowed length of a UDP packet, less the space required by the header and extras; however it MAY be any amount below this maximum. The Total value length field of the response extras MUST be the actual length of the complete value. The client, upon receipt of a Get Range response bearing Status 0x004 and a Message ID corresponding to its Get request, shall then know that it has received only the first portion of the value. The client MAY choose to request the remaining portion of the value by sending one or more Get Range requests.
The Get Range request is primarily intended for use over a UDP transport to request byte ranges of the value for a key. In the event that the Data version check fails to match that of the key, an error MUST be returned.
Extra data for get range request: Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| Flags | +---------------+---------------+---------------+---------------+ 4| Data version check | | | +---------------+---------------+---------------+---------------+ 12| Offset | +---------------+---------------+---------------+---------------+ 16| Length | +---------------+---------------+---------------+---------------+ Total 20 bytes
The Get Range request is primarily intended for use over a UDP transport to indicate the location of the bytes of the value for a key contained in a given packet. A client receives enough information in each Get Range extras to construct an appropriately sized buffer in its own memory and blindly insert the contents of the packet at the given byte offset.
Extra data for get range response: Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| Flags | +---------------+---------------+---------------+---------------+ 4| Data version check | | | +---------------+---------------+---------------+---------------+ 12| Offset | +---------------+---------------+---------------+---------------+ 16| Length | +---------------+---------------+---------------+---------------+ 20| Total value length | +---------------+---------------+---------------+---------------+ Total 24 bytes
This document does not introduce any new security considerations beyond those discussed in .