Skip to content
Browse files

Added some verbose/debug logging and a session sample

git-svn-id: http://svn.macosforge.org/repository/ruby/ControlTower/trunk@4886 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent c26c88a commit ca6b121d5d6a7aa171d9141913cb8eac4756c9f7 @jballanc jballanc committed
Showing with 25 additions and 0 deletions.
  1. +2 −0 lib/rack/session/gcd.rb
  2. +23 −0 sample/gcd_sessions.ru
View
2 lib/rack/session/gcd.rb
@@ -28,6 +28,7 @@ def initialize(sid, store)
@session_timer.cancel! unless @session_timer.nil?
time_remaining = @session_expires_at - Time.now
if time_remaining < 0
+ warn "Session #{@session_id} has expired" if $DEBUG
@session_store.delete(@session_id)
else
@session_timer = Dispatch::Source.timer(time_remaining, 500, 0.5, @session_access_queue, &@timer_block)
@@ -83,6 +84,7 @@ def generate_sid
end
def get_session(env, sid)
+ env['rack.errors'].puts("Searching through #{@sessions.length} live sessions") if $VERBOSE
session = @sessions[sid] if sid
unless sid and session
env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
View
23 sample/gcd_sessions.ru
@@ -0,0 +1,23 @@
+require 'rack/session/gcd'
+
+class SessionCheck
+ def call(env)
+ session = env['rack.session']
+ if session
+ if session[:num_accesses]
+ session[:num_accesses] += 1
+ msg = "This session has been accessed #{session[:num_accesses]} times"
+ else
+ session[:num_accesses] = 1
+ msg = 'This is the first time this session has been accessed'
+ end
+ else
+ msg = 'Whoops! No session...'
+ end
+ [200, {'Content-Type' => 'text/plain'}, msg]
+ end
+end
+
+$VERBOSE = true, $DEBUG = true
+use Rack::Session::GCD, :expire_after => 30
+run SessionCheck.new

0 comments on commit ca6b121

Please sign in to comment.
Something went wrong with that request. Please try again.