memcache.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 10:13:38 +0300
changeset 40 9cecd22e643a
parent 39 0e21a65074a6
child 41 540737bf6bac
permissions -rw-r--r--
*queuing, and add missing file
#ifndef MEMCACHE_H
#define MEMCACHE_H

/*
 * A libevent based memcached client that aims for high performance, concurrency and low latency.
 */

#include "config.h"

/*
 * Used to store the global information for a memcache context. A context contains both servers and active connections.
 */
struct memcache;

/*
 * A transaction.
 */
struct memcache_req;

/*
 * Keys used
 */
struct memcache_key {
    char *buf;
    size_t len;
};

/*
 * Object attributes
 */
struct memcache_obj {
    unsigned int flags;
    time_t exptime;
    size_t bytes;
    unsigned long long cas;
};

/*
 * Available commands
 */
enum memcache_command {
    FETCH_GET,
    STORE_SET,
    STORE_ADD,
    STORE_REPLACE,
    STORE_APPEND,
    STORE_PREPEND,
    STORE_CAS,
};

enum memcache_req_state {
    STATE_INVALID,

    STATE_ERROR,
};

/*
 * Callback used
 */
typedef int (*memcache_cb) (struct memcache_req *, void*);

/*
 * Allocate a new memcache context for use with other methods.
 */
struct memcache *memcache_alloc (memcache_cb cb_fn);

/*
 * Add a server to the pool of available servers.
 */
int memcache_add_server (struct memcache *mc, struct config_endpoint *endpoint, int max_connections);

/*
 * Attempt to fetch a key from the cache.
 */
struct memcache_req *memcache_fetch (struct memcache *mc, const struct memcache_key *key, void *cb_arg);

/*
 * Attempt to store a key into the cache
 */
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);

/*
 * Request state
 */ 
enum memcache_req_state memcache_req_state (struct memcache_req *req);

/*
 * Request key
 */
int memcache_req_key (struct memcache_req *req, const struct memcache_key *key);

/*
 * Request data
 */
int memcache_req_obj (struct memcache_req *req, const struct memcache_obj *obj);

#endif /* MEMCACHE_H */