Home > DeveloperSection > Forums > how to use memcache
aditya kumar Patel

Total Post:254

Posted on    October-31-2015 12:38 PM

 .NET Mvc 

 2 Reply(s)
 859  View(s)
Rate this:
how to use memcache

aditya kumar Patel

Total Post:254

Posted on    October-31-2015 12:39 PM

1. Install Memcached server in Windows

The latest Memcached version is 1.4.5, but the application doesn't support "-d install" parameter to install itself as Windows service.

So right now the 1.4.4 is still the option to go under Windows. Get a package from memcached 1.4.4 for Windows 32-bit from http://downloads.northscale.com/memcached-win32-1.4.4-14.zip.

Unzipped to a folder, then run the following command to install as win services
memcached.exe -d install

Start the server from the Microsoft Management Console or by running one of the following commands: 
memcached.exe -d start

2. Check Memcached installation

You can telnet to the default port 11211 to check the status:
telnel localhost 11211

Then use the command stats to check status

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Enyim.Caching;
using Enyim.Caching.Memcached;

namespace MemCching
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)


        protected void Button1_Click(object sender, EventArgs e)
            List<User> lst = new List<MemCching.User>();
            List<User> lst2 = new List<MemCching.User>();
            User ob = new MemCching.User();
            ob.UserID = "1";
            ob.UserName = "aditya";

            JsonSerializerSettings s = new JsonSerializerSettings();
            s.NullValueHandling = NullValueHandling.Ignore;
            s.MissingMemberHandling = MissingMemberHandling.Ignore;
            s.DefaultValueHandling = DefaultValueHandling.Ignore;
            bool b = false;
            bool c = false;
            string varCache = "SpibayProduct";
            MemcachedClient Cache = new MemcachedClient();
            string stringList = JsonConvert.SerializeObject(lst, Formatting.None, s);
            // a = Cache.Remove(varCache)
            if (Cache.Get(varCache) == null == true)
                b = Cache.Store(StoreMode.Add, varCache, stringList, DateTime.Now.AddDays(30));
                c = Cache.Store(StoreMode.Replace, varCache, stringList, DateTime.Now.AddDays(30));

  if (Cache.Get(varCache) == null == false)
                var str = Cache.Get(varCache);
                lst2 = JsonConvert.DeserializeObject<List<User>>(str.ToString());


    public class User
        public string UserID {get;set;}
        public string UserName {get;set;}

    <sectionGroup name="enyim.com">
      <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection,Enyim.Caching"/>

    <memcached protocol="Binary">
        <add address="" port="11211"/>
      <keyTransformer type="Enyim.Caching.Memcached.TigerHashKeyTransformer, Enyim.Caching" />

Modified On Oct-31-2015 01:04:39 PM

aditya kumar Patel

Total Post:254

Posted on    December-13-2015 9:52 AM

This is the best way to use memcache!!

Modified On Dec-15-2015 09:50:25 PM

Don't want to miss updates? Please click the below button!

Follow MindStick