0
votes

The Problem

It seem as thought no matter what values we configure memcached to use as an expiration time all of the items in the cache get an expiration time of 5 minutes.

What We Have Tried

  • Using an expiration of 0, all documentation indicates that this means the items should never expire.
  • Using an expiration of 600 seconds.
  • Using a Unix time stamp several hours in the future (eg. 1455058122).

In all cases when an item is cached and I retrieve the cachedump the expiration timestamp is only 5 minutes in the future.

This has been very frustrating as memcached works awesome except for this major flaw.

The Setup

  • .NET 3.5
  • Visual Studio 2015
  • NHibernate 3.1.0.4000
  • EnyimCached 2.3.0.0
  • Memcached 1.4.5_4_gaa7839e

Web.config

<enyimmemcache>
    <memcached protocol="Binary">
        <servers>
            <add key="MemcachedAddress" address="127.0.0.1" port="11211" />
            <!-- Add new servers here -->
        </servers>
        <socketPool connectionTimeout="00:00:02" />
        <cache region="system" expiration="0" priority="5" />
    </memcached>
</enyimmemcache>

Hibernate Config

<property name="cache.provider_class">NHibernate.Caches.EnyimMemcached.MemCacheProvider,NHibernate.Caches.EnyimMemcached</property>
<property name="cache.use_second_level_cache">true</property>

Stats.bat

@echo off>nul

setlocal EnableDelayedExpansion

IF "%1"=="-o" rm dump.log

set SAVESTAMP=%DATE:/=-%@%TIME::=:%

echo --------------[%SAVESTAMP%]-------------- >> dump.log

echo stats items | nc 127.0.0.1 11211 > statsitems

SET myvar=""

FOR /f "tokens=1,2,3 delims=:" %%i in (statsitems) do (
    if NOT %%j==!myvar! (
        SET myvar=%%j
        echo stats cachedump !myvar! 1000000 | nc 127.0.0.1 11211 >> dump.log
    )
)

rm statsitems
1

1 Answers

0
votes

The Solution

So as it turns out my sources of scattered information on the subject led me to use improper configuration set ups. Finally I decided to grab the Enyim source off github and investigate the issue myself, turns out the configuration in web.config wasn't even being used. Since Enyim was looking for the section with the name enyim.com and I was using com.enyim, oh symantics. The proper configurations are below.

Web.config

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

<enyim.com>
    <log factory="Enyim.Caching.Log4NetFactory, Enyim.Caching.Log4NetAdapter" />
    <memcached protocol="Binary">
      <servers>
        <add address="127.0.0.1" port="11211" />
        <!-- Add new servers here -->
      </servers>
      <socketPool connectionTimeout="00:00:02" />
    </memcached>
</enyim.com>

Hibernate.config

<property name="cache.provider_class">NHibernate.Caches.EnyimMemcached.MemCacheProvider,NHibernate.Caches.EnyimMemcached</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.default_expiration">2419200</property>

So there we have it. All items have an expiry of 28 days and memcached works perfectly.