terom@38: #ifndef MEMCACHE_H terom@38: #define MEMCACHE_H terom@38: terom@38: /* terom@38: * A libevent based memcached client that aims for high performance, concurrency and low latency. terom@38: */ terom@38: terom@38: #include "config.h" terom@38: terom@38: /* terom@38: * Used to store the global information for a memcache context. A context contains both servers and active connections. terom@38: */ terom@38: struct memcache; terom@38: terom@38: /* terom@38: * A transaction. terom@38: */ terom@38: struct memcache_req; terom@38: terom@38: /* terom@38: * Keys used terom@38: */ terom@38: struct memcache_key { terom@39: char *buf; terom@38: size_t len; terom@38: }; terom@38: terom@38: /* terom@38: * Object attributes terom@38: */ terom@38: struct memcache_obj { terom@38: unsigned int flags; terom@38: time_t exptime; terom@38: size_t bytes; terom@38: unsigned long long cas; terom@38: }; terom@38: terom@38: /* terom@38: * Available commands terom@38: */ terom@38: enum memcache_command { terom@38: FETCH_GET, terom@38: STORE_SET, terom@38: STORE_ADD, terom@38: STORE_REPLACE, terom@38: STORE_APPEND, terom@38: STORE_PREPEND, terom@38: STORE_CAS, terom@38: }; terom@38: terom@39: enum memcache_req_state { terom@38: STATE_INVALID, terom@38: terom@38: STATE_ERROR, terom@38: }; terom@38: terom@38: /* terom@38: * Callback used terom@38: */ terom@38: typedef int (*memcache_cb) (struct memcache_req *, void*); terom@38: terom@38: /* terom@38: * Allocate a new memcache context for use with other methods. terom@38: */ terom@38: struct memcache *memcache_alloc (memcache_cb cb_fn); terom@38: terom@38: /* terom@38: * Add a server to the pool of available servers. terom@38: */ terom@38: int memcache_add_server (struct memcache *mc, struct config_endpoint *endpoint, int max_connections); terom@38: terom@38: /* terom@38: * Attempt to fetch a key from the cache. terom@38: */ terom@38: struct memcache_req *memcache_fetch (struct memcache *mc, const struct memcache_key *key, void *cb_arg); terom@38: terom@38: /* terom@38: * Attempt to store a key into the cache terom@38: */ terom@38: struct memcache_req *memcache_store (struct memcache *mc, enum memcache_command cmd, const struct memcache_key *key, const struct memcache_obj *obj, void *cb_arg); terom@38: terom@38: /* terom@38: * Request state terom@38: */ terom@39: enum memcache_req_state memcache_req_state (struct memcache_req *req); terom@38: terom@38: /* terom@38: * Request key terom@38: */ terom@38: int memcache_req_key (struct memcache_req *req, const struct memcache_key *key); terom@38: terom@38: /* terom@38: * Request data terom@38: */ terom@38: int memcache_req_obj (struct memcache_req *req, const struct memcache_obj *obj); terom@38: terom@38: #endif /* MEMCACHE_H */