Ticket #3571: automatic_expiry_for_memcached_sessions.patch
| File automatic_expiry_for_memcached_sessions.patch, 3.0 kB (added by skaes, 3 years ago) |
|---|
-
actionpack/lib/action_controller/session/mem_cache_store.rb
old new 25 25 26 26 # Create a new CGI::Session::MemCache instance 27 27 # 28 # This constructor is used internally by CGI::Session. The28 # This constructor is used internally by CGI::Session. The 29 29 # user does not generally need to call it directly. 30 30 # 31 31 # +session+ is the session for which this instance is being 32 # created. The session id must only contain alphanumeric32 # created. The session id must only contain alphanumeric 33 33 # characters; automatically generated session ids observe 34 34 # this requirement. 35 35 # 36 # +option + is a hash of options for the initializer.The36 # +options+ is a hash of options for the initializer. The 37 37 # following options are recognized: 38 38 # 39 39 # cache:: an instance of a MemCache client to use as the 40 40 # session cache. 41 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. 48 # 42 49 # This session's memcache entry will be created if it does 43 50 # not exist, or retrieved if it does. 44 51 def initialize(session, options = {}) 45 52 id = session.session_id 46 53 unless check_id(id) 47 54 raise ArgumentError, "session_id '%s' is invalid" % id 48 end55 end 49 56 @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 = {} 52 60 end 53 61 54 62 # Restore session state from the session's memcache entry. … … 56 64 # Returns the session state as a hash. 57 65 def restore 58 66 begin 59 @ hash = @cache[@session_key]67 @session_data = @cache[@session_key] || {} 60 68 rescue 61 # Ignore session get failures.69 @session_data = {} 62 70 end 63 @hash = {} unless @hash64 @hash65 71 end 66 72 67 73 # Save session state to the session's memcache entry. 68 74 def update 69 75 begin 70 @cache [@session_key] = @hash76 @cache.set(@session_key, @session_data, @expires) 71 77 rescue 72 78 # Ignore session update failures. 73 79 end … … 85 91 rescue 86 92 # Ignore session delete failures. 87 93 end 88 @hash= {}94 @session_data = {} 89 95 end 90 96 end 91 97 end