MemCached for .net Developers



Hi friends, In this article I would like to share some useful information about MemCached for Dotnet Developers. MemCached is a distributed caching system and Simply put, it is nothing but, memory spread across multiple servers. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times database is accessed.


Advantages of MemCached:
  • MemCached is highly efficient in retrieving data for multiple clients.
  • Objects can be stored directly in MemCached.
  • MemCached uses binary serialization.
  • MemCached can run on UNIX, Windows and MacOS.
  • MemCached is distributed under a permissive free software license.
Pre-requisites:
  • Need to install MemCached server.
  • Need to install MemCached .NET client to access the MemCached servers.
How MemCached Works:

Server-side:
  • MemCached client communicates with server through TCP connection and default port is 11211.
  • MemCached server listens to the port configured, for any requests from MemCached clients.
  • Once the server receives a request from a client on the port, two-level hashing takes place.
    • First level hashing is when out of the server pool, MemCached client connects to the correct server.
    • Second level hashing is when the value is retrieved for the key provided.
  • The value is then returned to the client.
Client-side:
  • Opens connection with the server.
  • Sends commands like get(), set(), delete() to server.
  • Reads responses from server.
  • Closes the connection.
Two-level Hashing:


Step 1: The application requests keys “foo”, “bar” and “baz” using the client library, which calculates              key-hash values, determining which MemCached server should receive requests.
Step 2: MemCached client sends parallel requests to all relevant MemCached servers.
Step 3: MemCached servers send responses to the client library.
Step 4: MemCached client library aggregates responses for the application. MemCached client library              is responsible for sending requests to the correct servers.

MemCached Set-up:
Click here MemCached.exe to Download

Go to command prompt:
Run this command "c:/memcached/memcached.exe -d install"
then type "c:/memcached/memcached.exe -d start"
(To uninstall “memcached Server” service, in command-prompt, type sc delete “memcached Server”)

Run the Memcached server:

Go to Start -->Run --> and type services.msc
Ensure that “memcached Server” is up and running.
  • Default properties of MemCached are
    • MemCached server listens to port 11211
    • Memory limit is 64 MB.
  • Start → Run → and type regedit
    • Go to HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached Server.
    • Modify value for Key “ImagPath” to “c:\memcached\memcached.exe” -d runservice -m 512 (This increases memory limit of the server to 512 Mb)
    • ther options available to modify default values:
      To modify memory limit of the server: -m 1024
      To change port number that server listens to: -p 11211
      To modify maximum size allowed for storing an object: -I 32m (k for kilobytes, m for megabytes)
The maximum object size you can specify is 128MB, the default remains at 1MB.
Click here for Download .NET MemCached Client library.

Thanks,
www.pioneerscode.com




 

© 2012 Pioneers Code All Rights Reserved Pioneers Code