Sha256: 09703c8d0260feb445db7d16c47ea09f4ab15c6af033db32b5cb8ee08ca51631

Contents?: true

Size: 1.4 KB

Versions: 57

Compression:

Stored size: 1.4 KB

Contents

require 'spiderfw/controller/session'

module Spider
    
    class MemorySession < Session
        
        class << self
                
            
            def setup
                unless @sessions
                    @mutex ||= Mutex.new
                    @sessions ||= Hash.new
                end
                super
            end
        
            def []=(sid, data)
                @mutex.synchronize {
                    @sessions[sid] = {
                        :data => data,
                        :mtime => Time.now
                    }
                }
            end
        
            def [](sid)
                check_purge
                @mutex.synchronize{
                    @sessions[sid] ? @sessions[sid][:data] : nil
                }
            end
            
            def purge(life)
                @mutex.synchronize{
                    @sessions.each do |sid, session|
                        if (session[:mtime] + life < Time.now)
                            @sessions.delete(sid)
                        end
                    end
                }
            end
            
            def delete(sid)
                @mutex.synchronize{
                    @sessions.delete(sid)
                }
            end
            
        end
        
        
        def restore
            @data = self.class[@sid]
        end
        
        
    end
    
    
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/controller/session/memory_session.rb
spiderfw-1.0.0 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.39 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.38 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.37 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.35 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.34 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.33 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.32 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.31 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.30 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.29 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.28 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.27 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.26 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.26.pre1 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.25 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.24 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.23 lib/spiderfw/controller/session/memory_session.rb
spiderfw-0.6.22 lib/spiderfw/controller/session/memory_session.rb