Sha256: 6f2163f4e938a112d3bb504586158daf3042f7e09deaf5ae7dd803049efb8891
Contents?: true
Size: 1.46 KB
Versions: 4
Compression:
Stored size: 1.46 KB
Contents
require 'spiderfw/controller/session' module Spider class MemorySession < Session class << self def setup unless @sessions @sync ||= Sync.new @sessions ||= Hash.new end super end def []=(sid, data) @sync.lock(Sync::EX) @sessions[sid] = { :data => data, :mtime => Time.now } @sync.lock(Sync::UN) end def [](sid) check_purge @sync.lock(Sync::SH) sess = @sessions[sid] ? @sessions[sid][:data] : nil @sync.lock(Sync::UN) sess end def purge(life) @sync.lock(Sync::EX) @sessions.each do |sid, session| if (session[:mtime] + life < Time.now) @sessions.delete(sid) end end @sync.lock(Sync::UN) end def delete(sid) @sync.lock(Sync::EX) @sessions.delete(sid) @sync.lock(Sync::UN) end end def restore @data = self.class[@sid] end end end
Version data entries
4 entries across 4 versions & 1 rubygems