Intermediate Usage

The quick start section should cover most of the usage scenarios. However, the API is not restricted to such a simple approach to configuration. The client initialization can be broken down a bit to allow for more control:

   1:  //Create the server connection collection
   2:  ServerConnectionCollection servers = new ServerConnectionCollection();
   3:  //Add a server
   4:  servers.Add("127.0.0.1");
   5:  //Create a connection provider for the server collection
   6:  IConnectionProvider provider = new ConnectionProvider(servers);
   7:  //Create the client and save a value
   8:  MemcachedClient client = new MemcachedClient(provider);
   9:  ResponseCode response = client.Set("testKey", "this is some test data", DateTime.Now.AddSeconds(15));

This example performs the exact same operation as the quick start with a few more steps. It creates a ServerConnectionCollection and explicitly creates the IConnectionProvider with the server collection to be used by the client. This allows for custom connection providers to be used if the default is not satisfactory for the situation.

The ConnectionProvider class used in this example implements the IConnectionProvider interface and requires a collection of ServerConnection objects. The ServerConnectionCollection is a convenience class that implements IEnumerable<ServerConnection> so it may be used with connection providers.

After the connection provider is created it is then passed to the MemcachedClient class constructor. The MemcachedClient is now ready to send a command.

Still not complex enough for you? Tread lightly to the advanced usage page.

Last edited Aug 23, 2011 at 9:27 PM by JSanford42, version 5

Comments

No comments yet.