memcache: A memcached client library.

[ bsd3, database, library ] [ Propose Tags ] [ Report a vulnerability ]

A client library for a Memcached cluster. Memcached is an in-memory key-value store typically used as a distributed and shared cache. Clients connect to a group of Memcached servers and perform out-of-band caching for things like SQL results, rendered pages, or third-party APIs.

It uses the Memcached Meta Text protocol and requires memcached 1.6.0 or newer. Username/password authentication is supported through memcached's -Y authfile mode; the binary protocol and SASL authentication are no longer supported. It supports connecting to a single, or a cluster of Memcached servers. When connecting to a cluster, consistent hashing is used for routing requests to the appropriate server. Timeouts, retrying failed operations, and failover to a different server are all supported, as is Amazon ElastiCache auto discovery.

Multi-get is supported through the pipelined getMany. Keys containing whitespace or control bytes are sent using the protocol's base64 binary-key mode.

Basic usage is:

import qualified Database.Memcache.Client as M

mc <- M.newClient [M.ServerSpec "localhost" "11211" M.NoAuth] M.def
M.set mc "key" "value" 0 0
v <- M.get mc "key"

You should only need to import Database.Memcache.Client, but other modules are exposed for lower-level use. Version 0.4 is a breaking change from 0.3; see the changelog for details.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0, 0.0.1, 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.2.0.1, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.4.0.0
Change log CHANGELOG.md
Dependencies base (>=4.16 && <5), base64-bytestring (>=1.2.1.0), bytestring (>=0.11.4.0), data-default (>=0.7.1.1), errors (>=2.3.0), hashable (>=1.4.2.0), network (>=3.1.4.0), network-uri (>=2.6.4.2), resource-pool (>=0.2.3.2), text (>=1.2.5.0), time (>=1.11.1.1), unliftio (>=0.2.25.0), vector (>=0.12.3.1) [details]
License BSD-3-Clause
Copyright 2012-2026 David Terei.
Author David Terei <code@davidterei.com>
Maintainer David Terei <code@davidterei.com>
Uploaded by DavidTerei at 2026-10-19T06:44:33Z
Revised Revision 1 made by DavidTerei at 2026-10-19T06:51:34Z
Category Database
Home page https://github.com/dterei/memcache-hs#readme
Bug tracker https://github.com/dterei/memcache-hs/issues
Source repo head: git clone https://github.com/dterei/memcache-hs
Distributions LTSHaskell:0.3.0.2, Stackage:0.3.0.2
Reverse Dependencies 5 direct, 2 indirect [details]
Downloads 5653 total (16 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-10-19 [all 1 reports]

Readme for memcache-0.4.0.0

[back to package description]

memcache: Haskell Memcached Client

Hackage Hackage Dependencies BSD3 License CI Gitter

A client library for a memcached cluster.

It supports the Meta Text memcached protocol and username/password authentication. Keys containing whitespace or control bytes are sent using its base64 binary-key mode. The encoded key must still fit within 250 bytes. It supports connecting to a single, or a cluster of memcached servers. When connecting to a cluster, consistent hashing is used for routing requests to the appropriate server.

This library requires memcached 1.6.0 or newer, the first release with the meta commands. Against older servers every operation is rejected with ERROR.

Authentication uses a memcached auth file with -Y authfile, an experimental ASCII-protocol auth mode added in memcached 1.5.15; the old binary protocol -S SASL mode is not supported. Enabling -Y also disables binary and UDP protocols on the server. getMany uses quiet misses, so a server connection failure can be indistinguishable from a cache miss.

The client operations, including getMany, use direct Meta Text encoders and the Response type; the former request and response wrapper types are no longer provided.

Licensing

This library is BSD-licensed.

Tools

This library also includes a few tools for manipulating and experimenting with memcached servers.

  • OpGen -- A load generator for memcached. Doesn't collect timing statistics, other tools like mutilate already do that very well. This tool is useful in conjunction with mutilate.
  • Loader -- A tool to load random data of a certain size into a memcached server. Useful for priming a server for testing.

Architecture Notes

We're relying on Data.Pool for thread safety right now. Grabbing a connection from the pool (withResource) blocks other requests using that connection until the operation completes. getMany is the exception: it pipelines quiet Meta Text requests over one pooled connection.

Multiple connections through the pool abstraction allow concurrent operations and provide a simple performance path without requiring a separate pool implementation.

Either way, a pool is fine for now.

Other clients

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository:

  • git clone https://github.com/dterei/memcache-hs.git

Authors

This library is written and maintained by David Terei (code@davidterei.com).

Contributions have been made by the following great people: