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@41: * Object data terom@41: */ terom@41: struct memcache_buf { terom@41: char *data; terom@41: size_t len; terom@41: size_t offset; terom@41: }; terom@41: terom@41: /* terom@38: * Available commands terom@38: */ terom@38: enum memcache_command { terom@41: MEMCACHE_CMD_INVALID, terom@41: terom@41: MEMCACHE_CMD_FETCH_GET, terom@41: MEMCACHE_CMD_STORE_SET, terom@41: MEMCACHE_CMD_STORE_ADD, terom@41: MEMCACHE_CMD_STORE_REPLACE, terom@41: MEMCACHE_CMD_STORE_APPEND, terom@41: MEMCACHE_CMD_STORE_PREPEND, terom@41: MEMCACHE_CMD_STORE_CAS, terom@41: terom@41: MEMCACHE_CMD_MAX, terom@41: }; terom@41: terom@41: enum memcache_reply { terom@41: MEMCACHE_RPL_INVALID, terom@41: terom@41: MEMCACHE_RPL_ERROR, terom@41: MEMCACHE_RPL_CLIENT_ERROR, terom@41: MEMCACHE_RPL_SERVER_ERROR, terom@41: terom@41: // MEMCACHE_CMD_FETCH_* terom@41: MEMCACHE_RPL_VALUE, terom@41: MEMCACHE_RPL_END, terom@41: terom@41: // MEMCACHE_CMD_STORE_* terom@41: MEMCACHE_RPL_STORED, terom@41: MEMCACHE_RPL_NOT_STORED, terom@41: MEMCACHE_RPL_EXISTS, terom@41: MEMCACHE_RPL_NOT_FOUND, terom@41: terom@41: MEMCACHE_RPL_MAX, terom@38: }; terom@38: terom@39: enum memcache_req_state { terom@41: MEMCACHE_STATE_INVALID, terom@38: terom@41: MEMCACHE_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 */