require 'cgi' require 'cgi/session' class CGI #:nodoc:all class Session class CachetasticStore def check_id(id) #:nodoc:# /[^0-9a-zA-Z]+/ =~ id.to_s ? false : true end def initialize(session, options = {}) id = session.session_id unless check_id(id) raise ArgumentError, "session_id '%s' is invalid" % id end @session_key = id @session_data = {} end # Restore session state from the session's memcache entry. # # Returns the session state as a hash. def restore @session_data = Cachetastic::Caches::RailsSessionCache.get(@session_key) do {} end end # Save session state to the session's memcache entry. def update Cachetastic::Caches::RailsSessionCache.set(@session_key, @session_data) end # Update and close the session's memcache entry. def close update end # Delete the session's memcache entry. def delete Cachetastic::Caches::RailsSessionCache.delete(@session_key) @session_data = {} end def data @session_data end end end end