Class: CGI::Session::CachetasticStore
- Defined in:
- lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb
Overview
Allows Rails to use Cachetastic for it’s session store. The setting below needs to happen AFTER the gem has been required, obviously! In Rails 1.2.6 this is AFTER the initializer block.
ActionController::Base.session_store = :cachetastic_store
Instance Method Summary collapse
-
#check_id(id) ⇒ Object
:nodoc:#.
-
#close ⇒ Object
Update and close the session’s memcache entry.
-
#data ⇒ Object
:nodoc:#.
-
#delete ⇒ Object
Delete the session’s memcache entry.
-
#initialize(session, options = {}) ⇒ CachetasticStore
constructor
:nodoc:#.
-
#restore ⇒ Object
Restore session state from the session’s memcache entry.
-
#update ⇒ Object
Save session state to the session’s memcache entry.
Constructor Details
#initialize(session, options = {}) ⇒ CachetasticStore
:nodoc:#
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 17 def initialize(session, = {}) #:nodoc:# id = session.session_id unless check_id(id) raise ArgumentError, "session_id '%s' is invalid" % id end @session_key = id @session_data = {} end |
Instance Method Details
#check_id(id) ⇒ Object
:nodoc:#
13 14 15 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 13 def check_id(id) #:nodoc:# /[^0-9a-zA-Z]+/ =~ id.to_s ? false : true end |
#close ⇒ Object
Update and close the session’s memcache entry.
43 44 45 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 43 def close #:nodoc:# update end |
#data ⇒ Object
:nodoc:#
53 54 55 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 53 def data #:nodoc:# @session_data end |
#delete ⇒ Object
Delete the session’s memcache entry.
48 49 50 51 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 48 def delete #:nodoc:# Cachetastic::Caches::RailsSessionCache.delete(@session_key) @session_data = {} end |
#restore ⇒ Object
Restore session state from the session’s memcache entry.
Returns the session state as a hash.
31 32 33 34 35 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 31 def restore #:nodoc:# @session_data = Cachetastic::Caches::RailsSessionCache.get(@session_key) do {} end end |
#update ⇒ Object
Save session state to the session’s memcache entry.
38 39 40 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/rails_extensions/cgi_session_store.rb', line 38 def update #:nodoc:# Cachetastic::Caches::RailsSessionCache.set(@session_key, @session_data) end |