static public Method

MemCacheStore.new(session, options = {})

Create a new CGI::Session::MemCache instance

This constructor is used internally by CGI::Session. The user does not generally need to call it directly.

session is the session for which this instance is being created. The session id must only contain alphanumeric characters; automatically generated session ids observe this requirement.

options is a hash of options for the initializer. The following options are recognized:

cache:an instance of a MemCache client to use as the
session cache.
expires:an expiry time value to use for session entries in
the session cache. +expires+ is interpreted in seconds
relative to the current time if it’s less than 60*60*24*30
(30 days), or as an absolute Unix time (e.g., Time#to_i) if
greater. If +expires+ is +0+, or not passed on +options+,
the entry will never expire.

This session’s memcache entry will be created if it does not exist, or retrieved if it does.

Source Code

# File action_controller/session/mem_cache_store.rb, line 51
def initialize(session, options = {})
  id = session.session_id
  unless check_id(id)
    raise ArgumentError, "session_id '%s' is invalid" % id
  end
  @cache = options['cache'] || MemCache.new('localhost')
  @expires = options['expires'] || 0
  @session_key = "session:#{id}"
  @session_data = {}
  # Add this key to the store if haven't done so yet
  unless @cache.get(@session_key)
    @cache.add(@session_key, @session_data, @expires)
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.