I've attached a quick and dirty patch that adds support for GET &
POSTs (libevents builtin HTTP client doesn't support PUTs or DELETEs
yet) that illustrates the idea. It leaks, and seems to truncate data
in odd places but I think it gets the point across.
vijay
At one point I wrote a web app that had a REST interface to run out in
front of memcached. The idea being that the REST front-end could be
load balanced and configured such that clients only need to know one
address for the cache. Then operations folks and what not could manage
the number of caches and their arrangements behind that. The interface
was something like this...
Actually, when you look at PUT and POST in their pure forms the
mapping is actually a little odd...
GET /{cache_name}/{key} = get
DELETE /{cache_name}/{key} = delete
PUT /{cache_name}/{key} = set
POST /{cache_name}/{key} = ?
I map PUT to "set" because in this case the user knows the destination
of the resource, the user knows the full URI they want the resource to
have. I think this is the purest mapping of PUT, as it ties well to
how set works. The question then is how does one support the memcache
"add" and "replace"? POST is meant for sending a resource into a
factory location where the user does NOT know the final URI. Following
this constraint, there isn't a clear mapping of POST to the memcache
protocol.
A slightly more overloaded mapping might look like...
PUT /{cache_name}/{key} = add
POST /{cache_name}/{key} = set
Here, POST is being used incorrectly and PUT should arguably be used
as "replace" not "add".
Maybe the best thing to do is PUT=set and POST is overloaded to
support the more exotic use cases like "add", "replace", and maybe
even "incr"/"decr". That's the industry standard REST style I think.
Try and use GET/PUT/DELETE, give up and overload the shit out of POST
:P
Oh, and "cache_name" above was meant to be separate named memcache
clusters for different applications...
Memcached is usually used for performance and scaling, and one of the
issues one encounters down that road is network load. We are extremely
latency sensitive, and we ended up rewriting the structure of both our
values and our keys to reduce their size (keys get sent back on a
multiget), which ended up yielding significant performance benefits
for us.
For folks that don't have this problem, and/or typically have very
large values stored, the http front end might be a nice thing to have.
It's just worth bearing in mind that it has a few negative
consequences as well.
-josh
It's unfortunate that libevent doesn't support PUT/DELETE (yet!!)
because those 4 verbs would cover most common uses cases. I think
it'd be pretty easy to add that in, however.
vijay
1 http://en.wikipedia.org/wiki/Representational_State_Transfer
2 http://wiki.apache.org/couchdb/HTTP_Document_API