Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
an Erlang memcached client application
Erlang C++
tree: 4af6e912ee

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
make
.gitignore
LICENSE
Makefile
README.markdown
README.txt

README.markdown

Description

mcache is an erlang memcached client application. It utilizes many new features to improve performance such as NIF (only from R13B03 on), dynamic compiling modules.

Start/Stop/Configuration

mcache is an OTP application. You may start or stop it as following:

application:start(mcache)
application:stop(mcache).

It requires the following configuration (in -config <ConfigFile> or sys.config)

{mcache,
    [
        {pools,[
            [{name, generic}, % Pool name is "generic"
             {servers, 
                [ 
                    { {1,0,0,1}, 11211, 256 },   % Servers definition. IP address should be in {A,B,C,D} format
                    { {1,0,0,2}, 11211, 256 }
                ]}
            ]
        ]}
    ]
}

Usage

  1. Get a single key.

    mcache:get(Class, Key).
    

    For example: mcache:get(my.friends, foobar) gets the key "my.friends:foobar"

    Which memcached server is selected? The following steps go:

    1. Get expiry config from Class. Default is {generic, 300} (i.e. {PoolName, ExpireSeconds})
    2. Get the server continuum from the pool name. (in ketama's consistent hashing algorithm)
    3. Calc the server from Key's MD5 hash value according the above continuum.

    Return values:

    • undefined, if key not found.
    • Value, any other values.
  2. Get multiple keys.

    mcache:mget(Class, [Key|_]).
    

    Note: it gets all the keys with the same Class.

  3. Set a key and value.

    mcache:set(Class, Key, Value, Format, Expiry)
    

    Class is any atom or iolist.

    Key can be any iolist.

    Format can be the following atoms:

    • raw, an iolist.
    • native, any Erlang term (uses term_to_binary())
    • json, convert to json string (using an enhanced version of EEP0018)
    • int, data in <<Int:32>> format.

    Expiry can be as following:

    • default, uses ExpireConfig
    • infinity, no expiration
    • {X, seconds}, or minutes, hours, days, etc.
    • Integer, any numeric seconds.

    This argument can be ignored. default is used in this case.

    Return

    • A list of {Key, Value} pairs. The key doesn't contain Class part.
    • Missing keys won't show in the list.
    • If all keys are missing, an empty list ([]) is returned.
Something went wrong with that request. Please try again.