class Qwik::SessionDB

Constants

DEFAULT_EXPIRE_TIME

Public Class Methods

new(config) click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 44
def initialize(config)
  @config = config
  @config.cache_dir.path.check_directory
  @path = @config.cache_dir.path+'sid'
  @path.check_directory
  @expire_time = DEFAULT_EXPIRE_TIME
end

Public Instance Methods

clear(sid) click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 65
def clear(sid)
  file = path(sid)
  return nil if ! file.exist?
  file.unlink # delete it
end
generate_sid() click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 52
def generate_sid
  str = Time.now.to_i.to_s+':'+rand.to_s
  return str.md5hex
end
get(sid) click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 71
def get(sid)
  return if sid.nil? || sid.empty?
  file = path(sid)
  return nil if ! file.exist?
  mtime = file.mtime
  diff = Time.now.to_i - mtime.to_i
  if @expire_time < diff
    clear(sid)
    return nil
  end
  str = file.read
  return str
end
path(sid) click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 57
def path(sid)
  @path + sid
end
put(sid, user) click to toggle source
# File vendor/qwik/lib/qwik/common-session.rb, line 61
def put(sid, user)
  path(sid).put(user)
end