1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3465 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2006-01-22 22:21:26 +00:00
parent 554aa2e1e9
commit 6236d518f2
2 changed files with 20 additions and 12 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Added the possibility to specify atomatic expiration for the memcachd session container #3571 [Stefan Kaes]
* Change layout discovery to take into account the change in semantics with File.join and nil arguments. [Marcel Molina Jr.] * Change layout discovery to take into account the change in semantics with File.join and nil arguments. [Marcel Molina Jr.]
* Raise a RedirectBackError if redirect_to :back is called when there's no HTTP_REFERER defined #3049 [kevin.clark@gmail.com] * Raise a RedirectBackError if redirect_to :back is called when there's no HTTP_REFERER defined #3049 [kevin.clark@gmail.com]

View file

@ -33,12 +33,19 @@ begin
# characters; automatically generated session ids observe # characters; automatically generated session ids observe
# this requirement. # this requirement.
# #
# +option+ is a hash of options for the initializer. The # +options+ is a hash of options for the initializer. The
# following options are recognized: # following options are recognized:
# #
# cache:: an instance of a MemCache client to use as the # cache:: an instance of a MemCache client to use as the
# session cache. # 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 its 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 # This session's memcache entry will be created if it does
# not exist, or retrieved if it does. # not exist, or retrieved if it does.
def initialize(session, options = {}) def initialize(session, options = {})
@ -47,8 +54,9 @@ begin
raise ArgumentError, "session_id '%s' is invalid" % id raise ArgumentError, "session_id '%s' is invalid" % id
end end
@cache = options['cache'] || MemCache.new('localhost') @cache = options['cache'] || MemCache.new('localhost')
@expires = options['expires'] || 0
@session_key = "session:#{id}" @session_key = "session:#{id}"
@hash = {} @session_data = {}
end end
# Restore session state from the session's memcache entry. # Restore session state from the session's memcache entry.
@ -56,18 +64,16 @@ begin
# Returns the session state as a hash. # Returns the session state as a hash.
def restore def restore
begin begin
@hash = @cache[@session_key] @session_data = @cache[@session_key] || {}
rescue rescue
# Ignore session get failures. @session_data = {}
end end
@hash = {} unless @hash
@hash
end end
# Save session state to the session's memcache entry. # Save session state to the session's memcache entry.
def update def update
begin begin
@cache[@session_key] = @hash @cache.set(@session_key, @session_data, @expires)
rescue rescue
# Ignore session update failures. # Ignore session update failures.
end end
@ -85,7 +91,7 @@ begin
rescue rescue
# Ignore session delete failures. # Ignore session delete failures.
end end
@hash = {} @session_data = {}
end end
end end
end end