Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3465

Show
Ignore:
Timestamp:
01/22/06 22:21:26 (3 years ago)
Author:
david
Message:

Added the possibility to specify atomatic expiration for the memcachd session container (closes #3571) [Stefan Kaes]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r3462 r3465  
    11*SVN* 
     2 
     3* Added the possibility to specify atomatic expiration for the memcachd session container #3571 [Stefan Kaes] 
    24 
    35* Change layout discovery to take into account the change in semantics with File.join and nil arguments. [Marcel Molina Jr.] 
  • trunk/actionpack/lib/action_controller/session/mem_cache_store.rb

    r525 r3465  
    2626        # Create a new CGI::Session::MemCache instance 
    2727        # 
    28         # This constructor is used internally by CGI::Session. The 
     28        # This constructor is used internally by CGI::Session. The 
    2929        # user does not generally need to call it directly. 
    3030        # 
    3131        # +session+ is the session for which this instance is being 
    32         # created. The session id must only contain alphanumeric 
     32        # created. The session id must only contain alphanumeric 
    3333        # characters; automatically generated session ids observe 
    3434        # this requirement. 
    3535        # 
    36         # +option+ is a hash of options for the initializer. The 
     36        # +options+ is a hash of options for the initializer. The 
    3737        # following options are recognized: 
    3838        # 
    3939        # cache::  an instance of a MemCache client to use as the 
    4040        #      session cache. 
     41        # 
     42        # expires:: an expiry time value to use for session entries in 
     43        #     the session cache. +expires+ is interpreted in seconds 
     44        #     relative to the current time if itÂ’s less than 60*60*24*30 
     45        #     (30 days), or as an absolute Unix time (e.g., Time#to_i) if 
     46        #     greater. If +expires+ is +0+, or not passed on +options+, 
     47        #     the entry will never expire. 
    4148        # 
    4249        # This session's memcache entry will be created if it does 
     
    4653          unless check_id(id) 
    4754            raise ArgumentError, "session_id '%s' is invalid" % id 
    48              end 
     55          end 
    4956          @cache = options['cache'] || MemCache.new('localhost') 
    50               @session_key = "session:#{id}" 
    51               @hash = {} 
     57          @expires = options['expires'] || 0 
     58          @session_key = "session:#{id}" 
     59          @session_data = {} 
    5260        end 
    5361 
     
    5765        def restore 
    5866          begin 
    59             @hash = @cache[@session_key] 
     67            @session_data = @cache[@session_key] || {} 
    6068          rescue 
    61             # Ignore session get failures. 
     69            @session_data = {} 
    6270          end 
    63           @hash = {} unless @hash 
    64               @hash 
    6571        end 
    6672 
     
    6874        def update 
    6975          begin 
    70             @cache[@session_key] = @hash 
     76            @cache.set(@session_key, @session_data, @expires) 
    7177          rescue 
    7278            # Ignore session update failures. 
     
    8692            # Ignore session delete failures. 
    8793          end 
    88              @hash = {} 
     94          @session_data = {} 
    8995        end 
    9096      end