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.



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

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

Instance Method Details

#[]=(key, val) ⇒ Object



83
84
85
86
87
# File 'lib/mini_mime.rb', line 83

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

#fetch(key, &blk) ⇒ Object



89
90
91
# File 'lib/mini_mime.rb', line 89

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