【问题标题】:Memcache - Cached Data is always nullMemcache - 缓存数据始终为空
【发布时间】:2017-05-07 20:12:56
【问题描述】:

下面是我尝试在控制台应用程序中使用Memcache

App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="enyim.com"/>
       <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection,Enyim.Caching"/>
   </configSections>

 <startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>

<enyim.com>
  <memcached protocol="Binary">
    <severs>
      <add address="127.0.0.1" port="11211"/>
    </severs>

   </memcached>
  </enyim.com>
 </configuration>

C#

static void Main(string[] args)
    {
        DateTime dt = DateTime.Now;
        try
        {

            using (MemcachedClient memcache = new MemcachedClient())
            {
                string cachedTime = memcache.Get<string>("CachedTime");
                if (cachedTime == null)
                {
                    memcache.Store(Enyim.Caching.Memcached.StoreMode.Set, "CachedTime", DateTime.Now.ToString());
                 cachedTime = memcache.Get<string>("CachedTime");
                }

                Console.WriteLine(cachedTime);
                Console.WriteLine(dt);
            }   
        }
        catch (Exception ex)
        {

        }
    }

每次cachedDate的值为NULL

【问题讨论】:

    标签: c# asp.net caching memcached enyim.caching


    【解决方案1】:

    将 App.Config 更改为以下内容,它应该可以工作:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <sectionGroup name="enyim.com">
          <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
        </sectionGroup>
      </configSections>
    
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
    
      <enyim.com>
        <memcached>
          <servers>
            <add address="127.0.0.1" port="11211" />
          </servers>
          <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:00:10" deadTimeout="00:02:00" />
        </memcached>
      </enyim.com>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      相关资源
      最近更新 更多