This project is read-only.

Project Description
Miramemcachedsession is a pure memcached based implementation of a .net SessionStateProvider. This can be used in load-balanced environments with short lived sessions. This provider should only be used in very specific scenarios. It's developed in the c# language.


The memcached session provider should be used very carefully and only in specific setups. Always use a separate memcached instance / cluster to separate session data from cache data. Since session data is more critical than cache. This article explains why one shouldn't use memcached as a sessionstore http://dormando.livejournal.com/495593.html.
Internally the api requires that session data needs to get locked for the duration of a request, we solved this by using a lockkey in memcached. This should cover most race conditions.

Memcached_As_SessionStore_Infrastructure_Setup.png

Configuration
- application name : you can configure multiple applications to use the same memcached instance / cluster for session data. It is essential to provide a unique applicationname.
- lock timeout: The maximum duration that a process can lock the session data, this should be configurated at MIN(sessiontimeout, requesttimeout)

 

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="mirabeau">
      <!-- This section must be used to configure the sessionstate provider, do not use this section for normal caching. -->
      <section name="memcachedsessionstate" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
    </sectionGroup>
    
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  
  <appSettings></appSettings>
  <!-- 
    Use this section as a template if you're connecting to regular memcached servers.
    Note: you must have the enyim.com/memcached section if you're using the parameterless constructor of EnyimMemcachedClient.
  -->
  <mirabeau>
    <!-- you can use protocol="Text" if your memcached is < 1.3 but you should probably upgrade -->
    <memcachedsessionstate protocol="Binary">
      <servers>
        <!-- make sure you use the same ordering of nodes in every configuration you have -->
        <add address="127.0.0.1" port="11211" />
        <!--<add address="127.0.0.1" port="20004" />
        <add address="127.0.0.1" port="20006" />
        <add address="127.0.0.1" port="20008" />-->
      </servers>
      <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:10:00" deadTimeout="00:00:10" />
      <!--
      <locator type="Enyim.Caching.Memcached.KetamaNodeLocator, Enyim.Caching" />
      <keyTransformer type="add your type here" />
      <transcoder type="add your type here" />
      -->
      <!-- uncomment the section below if your memcached instance requires authentication 
      
      <authentication type="Enyim.Caching.Memcached.PlainTextAuthenticator" zone="AUTHZ" userName="USER NAME" password="PASSWORD" />
      
      -->
    </memcachedsessionstate>
  </mirabeau>
  <system.web>
    <sessionState
      cookieless="false"
      regenerateExpiredSessionId="true"
      mode="Custom"
      timeout="60"
      customProvider="MemcachedSessionProvider">
      <providers>
        <add name="MemcachedSessionProvider"
          type="Mirabeau.Web.Session.MemcachedSessionStateStoreProvider"
          />
      </providers>
    </sessionState>
  </system.web>
</configuration>

Last edited Oct 29, 2010 at 9:52 AM by Ruzzie, version 5