netcached is a lightweight, high performance .NET client for memcached protocol. It is fully compliant with Memcached protocol and also has support for in-memory databases such as Couchbase (formerly Membase).

Note: Full technical documentation coming soon

Source code is available for download here and for browsing here.

Key features

  • supports all operations compliant with Memcached protocol
  • consistent hashing and key distribution over multiple servers (Ketama implementation)
  • socket pooling and reuse for high performance read/write operations
  • concurrency handling for multithreaded environments
  • optional data compression using Deflate and GZip algorithms
  • serialization of all data types

Coming soon
  • support for vBuckets
  • server statistics and analysis

Usage examples

Client creation and configuration
// Create client from configuration (App.config)
MemcachedClient client = MemcachedClient.CreateFromConfiguration();

// Create client manually
MemcachedClient client = new MemcachedClient("localhost", 11211);

Basic operations
client.Set("someKey", "some value...");

string fetchedValue = client.Get<string>("someKey");  // Read the stored value

// Multi-get
string[] keys = new string[] {"key1", "key2", "key3"};
List<RetrievedItem> items = client.Get(keys);

// delete all entries on all servers
client.FlushAllEntries();

XML configuration (App and Web config)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="netcached" type="Netcached.Configuration.NetcachedConfigurationSection, Netcached" />
  </configSections>
  <netcached maxSocketsPerServer = "5" compressionAlgorithm="Deflate" compressionThreshold ="512">
    <servers>
      <add address="localhost" port="11211" sendReceiveTimeout="1100" />
      <add address="some.server.com" port="11211" sendReceiveTimeout="500" />
    </servers>
  </netcached>
</configuration>

Last edited Nov 14, 2012 at 3:48 PM by VedranK, version 7