first stab at a C API

Evan Martin martine@danga.com
21 Aug 2003 22:36:23 -0700


--=-gFraGkq9rYuzecL4carf
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is super-basic:  only connects to localhost, only has get and set.
The plan is this:
 - buffer reads (readline() should do a full read and scan for newlines)
 - don't buffer writes (the kernel buffers it anyway / TCP_CORK)

I'm not sure how the functions should look.  I'll attach my header.
I figure that eventually, we'd like something like get() to:
 - support printf-style formatting: get("user:%d", userid)
 - support hash keys: should these be ints or char* and len?
and maybe:
 - support some sort of serialization/deserialization callbacks(?)
but that produces a Windowsean function with 10 arguments.

Also, I took a shot at allowing weighting without using an array of
buckets.  Instead, we use the linked list of servers, but that means
this is O(n) * number of time we retry to find a live server.

If anyone wants to comment on my C code, I'd appreciate it.
You can read it at http://bunny.darktech.org/svn/memcache-c , and you
can check it out with this subversion command:
  svn checkout http://bunny.darktech.org/svn/memcache-c mydestdir

-- 
Evan Martin
martine@danga.com
http://neugierig.org

--=-gFraGkq9rYuzecL4carf
Content-Disposition: attachment; filename=memcache.h
Content-Type: text/x-c-header; name=memcache.h; charset=UTF-8
Content-Transfer-Encoding: 7bit

#ifndef MEMCACHE_H
#define MEMCACHE_H

#include <time.h>  /* time_t */

typedef struct _MemCacheClient MemCacheClient;

MemCacheClient* memcachec_new(void);

void* memcachec_get(MemCacheClient *mc, char *key, int *rlen);
int   memcachec_set(MemCacheClient *mc, char *key,
                    void *val, int len, time_t exp);


#endif /* MEMCACHE_H */

--=-gFraGkq9rYuzecL4carf--