Class: Innate::Session
- Inherits:
-
Object
- Object
- Innate::Session
- Includes:
- Optioned
- Defined in:
- lib/innate/session.rb,
lib/innate/session/flash.rb
Overview
Mostly ported from Ramaze, but behaves lazy, no session will be created if no session is used.
We keep session data in memory until #flush is called, at which point it will be persisted completely into the cache, no question asked.
You may store anything in here that you may also store in the corresponding store, usually it’s best to keep it to things that are safe to Marshal.
The Session instance is compatible with the specification of rack.session.
Since the Time class is used to create the cookie expiration timestamp, you will have to keep the ttl in a reasonable range. The maximum value that Time can store on a 32bit system is:
Time.at(2147483647) # => Tue Jan 19 12:14:07 +0900 2038
The default expiration time for cookies and the session cache was reduced to a default of 30 days. This was done to be compatible with the maximum ttl of MemCache. You may increase this value if you do not use MemCache to persist your sessions.
Defined Under Namespace
Classes: Flash
Instance Attribute Summary collapse
-
#cookie_set ⇒ Object
readonly
Returns the value of attribute cookie_set.
-
#flash ⇒ Object
readonly
Returns the value of attribute flash.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key, value = nil) ⇒ Object (also: #[])
-
#flush(response = @response) ⇒ Object
Additional interface.
-
#initialize(request, response) ⇒ Session
constructor
A new instance of Session.
- #sid ⇒ Object
-
#store(key, value) ⇒ Object
(also: #[]=)
Rack interface.
Methods included from Optioned
Constructor Details
Instance Attribute Details
#cookie_set ⇒ Object (readonly)
Returns the value of attribute cookie_set.
48 49 50 |
# File 'lib/innate/session.rb', line 48 def @cookie_set end |
#flash ⇒ Object (readonly)
Returns the value of attribute flash.
48 49 50 |
# File 'lib/innate/session.rb', line 48 def flash @flash end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
48 49 50 |
# File 'lib/innate/session.rb', line 48 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
48 49 50 |
# File 'lib/innate/session.rb', line 48 def response @response end |
Instance Method Details
#clear ⇒ Object
73 74 75 76 |
# File 'lib/innate/session.rb', line 73 def clear cache.delete(sid) @cache_sid = nil end |
#delete(key) ⇒ Object
69 70 71 |
# File 'lib/innate/session.rb', line 69 def delete(key) cache_sid.delete(key) end |
#fetch(key, value = nil) ⇒ Object Also known as: []
64 65 66 |
# File 'lib/innate/session.rb', line 64 def fetch(key, value = nil) cache_sid[key] end |
#flush(response = @response) ⇒ Object
Additional interface
80 81 82 83 84 85 86 |
# File 'lib/innate/session.rb', line 80 def flush(response = @response) return if !@cache_sid or @cache_sid.empty? flash.rotate! cache.store(sid, cache_sid, :ttl => .ttl) (response) end |
#sid ⇒ Object
88 89 90 |
# File 'lib/innate/session.rb', line 88 def sid @sid ||= || generate_sid end |
#store(key, value) ⇒ Object Also known as: []=
Rack interface
59 60 61 |
# File 'lib/innate/session.rb', line 59 def store(key, value) cache_sid[key] = value end |