回答

1

明白了這個pluralsight視頻由理查德Seroter工作。

步驟:

添加以下NuGet包:EnyimMemCached

然後在你的web配置添加此的configSections節點:

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

然後添加下面這只是 system.web節點(所以它是system.web的兄弟節點)。一定要與你的elasticache端點更換網址和端口:

<enyim.com> 
    <memcached> 
     <servers> 
     <add address="...your elasticache url here...." port="your port here..."></add> 
     </servers> 
    </memcached> 
    </enyim.com> 

然後在我看來動作我叫設置緩存值,並讀出來。它僅在已發佈並在AWS上運行時纔有效(不在本地工作):

public ActionResult Index() 
     { 
      var client = new MemcachedClient(); 

      string myCacheKey = "MyCacheKey"; 
      client.Store(Enyim.Caching.Memcached.StoreMode.Set, myCacheKey, "If you see this it worked."); // set the cache. 
      string myCachedString = client.Get<string>(myCacheKey); 

      ViewBag.MyCache = myCachedString ?? "**** SORRY, DIDN'T WORK..***.."; 
      return View(); 

     } 

跳這有助於某人。