Using Memcached in Eiffel applications


Server applications often have the need to maintain state information between client calls, apart from the usual need to make data persistent. The latter is typically implemented with some database system. Examples of such state information is user session data (context) or generated data sets (data cache) obtained from the persistent data store via time costly database queries.

In single-process server applications this can be achieved in Eiffel by using the once mechanism and an instance of DS_HASH_TABLE [G, K] where keys typically represent user or client sessions and the items represent state information. Obviously, in multi-process server applications this solution is not possible, since objects are not shared between processes.

The need for maintaining state information in a multi-process environment arose early in web server based server applications and has been elegantly solved by  Memcached. Memcached is a widely used and high performance solution for state and data cache management. It runs on Linux and Windows and there exists a Debian/Ubuntu? package memcached. There also exist a number of language bindings for the Memcache C API. The Debian/Ubuntu? package python-memcache contains the Python bindings.

The aim of this project is to provide an Eiffel interface and set of classes for interfacing with Memcached via the Memcache C API.

Memcached & the Memcache C API

Memcached runs as a separate server/daemon process. There currently exist two (2) different C API:s for communicating with Memcached. Note the slightly different names!

  •  libmemcache. This is the original C library. It is no longer under active development. However this is the C API that has been used for many years and for which there exist Ubuntu/Debian? packages. The Ubuntu/Debian? package libmemcache0 contains the runtime C libraries and libmemcache-dev contains the development headers.

Primary objectives

  1. Wrap the set (key: STRING, value: STRING) and get (key: STRING): STRING functions in the libmemcache C API.
  1. Decide on which C API to wrap!
  1. Wrap it!


  1.  Memcached home page.
  1.  Memcached client API:s and libraries.
  1.  Memcached FAQ.
  1.  Memcached documentation resources.
  1.  Linux Journal article on Memcached.
  1.  Wikipedia article on Memcached.