class TimeLimitedStorage

一定時間以上参照されなかったデータを自動的に忘れていく連想配列っぽいもの。 デフォルトの最低有効期限(expire)は1800秒(30分)。expireより長くオブジェクトが保持される可能性がある。

Public Class Methods

new(key_class=Object, val_class=Object, expire = 1800) click to toggle source
Calls superclass method WeakStore.new
# File core/lib/weakstorage.rb, line 46
def initialize(key_class=Object, val_class=Object, expire = 1800)
  @key_class, @val_class, @expire, @repository, @last_modified = key_class, val_class, expire, gen_storage, Time.new.freeze
  super()
end

Public Instance Methods

[](key) click to toggle source
# File core/lib/weakstorage.rb, line 51
def [](key)
  atomic{
    result = if storage.has_key?(key)
               storage[key]
             elsif @repository.has_key?(key)
               @_storage[key] = @repository[key] end
    repository
    result } end
Also aliased as: get
[]=(key, val) click to toggle source
# File core/lib/weakstorage.rb, line 61
def []=(key, val)
  type_strict key => @key_class, val => @val_class
  atomic{
    storage[key] = val
    @repository.delete(key) if(@repository.has_key?(key))
    repository }
end
Also aliased as: store
get(key)
Alias for: []
has_key?(key) click to toggle source
# File core/lib/weakstorage.rb, line 70
def has_key?(key)
  atomic{
    result = if storage.has_key?(key)
               true
             elsif @repository.has_key?(key)
               @_storage[key] = @repository[key]
               true end
    repository
    result } end
inspect() click to toggle source
# File core/lib/weakstorage.rb, line 80
def inspect
  atomic{ "#<TimeLimitedStorage(#{@key_class} => #{@val_class}): #{storage.size}>" }
end
store(key, val)
Alias for: []=