Class: MiniMime::Db::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_mime.rb

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ Cache

Returns a new instance of Cache.



65
66
67
68
# File 'lib/mini_mime.rb', line 65

def initialize(size)
  @size = size
  @hash = {}
end

Instance Method Details

#[]=(key, val) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/mini_mime.rb', line 70

def []=(key,val)
  rval = @hash[key] = val
  if @hash.length > @size
    @hash.shift
  end
  rval
end

#fetch(key, &blk) ⇒ Object



78
79
80
# File 'lib/mini_mime.rb', line 78

def fetch(key, &blk)
  @hash.fetch(key, &blk)
end