Oct 16 2009

Memcached for NHibernate configuration attributes

Category: zvolkov @ 14:01

In my original article on using Memcached w/ NHibernate I mentioned a few configuration attributes to set in your session-factory properties. In this post I want to provide a definitive list of the settings, based on the actual source code of NHibernate.Caches.MemCache.dll version 2.1.0.4000.

  • cache.region_prefix or regionPrefix (string): when NH's Memcache Provider is asked to store an item, it builds the key to pass to the Memcached client DLL. This key is built as [regionPrefix][regionName]@[key]. The regionPrefix is what specified by this parameter, while regionName is built by the NHibernate core library as [cache.region_prefix].[cacheRegionName] where cache.region_prefix is another session-factory level setting. As you can see, either of regionPrefix or cache.region_prefix can be used to achieve the same effect. Since cache.region_prefix is a generic setting and regionPrefix is a provider-specific, I recommend using cache.region_prefix instead. Default is "" (empty string).
  • cache.default_expiration or expiration (Int32): since NH Contrib 2.1 cache.default_expiration is the new setting name that should be used instead of expiration to specify number of seconds after which the cache item must be invalidated. Default value is 300 seconds. The old name is still supported for backward compatibility.
  • compression_enabled (Bool): enables automatic compression of large values (longer than 30720 bytes, not currently configurable from NHibernate) using GZip. The purpose of the compression is to reduce network bandwith so compression/decompression is performed on the client side. If your cache resides on the same server as the application, it may be a good idea to turn this off. Default is true.

Following descriptions came from this post. I added the default values by looking at the Memcached.ClientLibrary.dll with Reflector.

  • failover (bool): If this flag is set to true and a socket fails to connect,  the pool will attempt to return a socket from another server if one exists.  If set to false, then getting a socket will return null if it fails to connect to the requested server. Default is true.
  • initial_connections (Int32): the initial number of connections per server setting in the available pool. Default is 3.
  • maintenance_sleep (Int64): the sleep time(in milliseconds) between runs of the pool maintenance thread. If set to 0, then the maintenance thread will not be started. Default is 5000.
  • max_busy (Int64): the maximum busy time(in milliseconds) for threads in the busy pool. Default is 300000.
  • max_connections (Int32): the maximum number of spare connections allowed in the available pool. Default is 10.
  • max_idle (Int64): the maximum idle time for threads in the available pool. Default is 180000.
  • min_connections (Int32): the minimum number of spare connections to maintain in the available pool. Default is 3.
  • nagle (bool): the Nagle algorithm flag for the pool. If false, will turn off Nagle's algorithm on all sockets created. Default is true.
  • socket_timeout (Int32): the socket timeout(in milliseconds) for reads. Default is 10000.
  • socket_connect_timeout (Int32): the socket timeout(in milliseconds) for connects. Default is 50.

Tags:

Comments

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading