Class: I18n::Backend::Http::LRUCache

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/backend/http/lru_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(size = 10) ⇒ LRUCache

Returns a new instance of LRUCache.



6
7
8
9
10
# File 'lib/i18n/backend/http/lru_cache.rb', line 6

def initialize(size = 10)
  @size = size
  @store = {}
  @lru = []
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
21
# File 'lib/i18n/backend/http/lru_cache.rb', line 18

def [](key)
  set_lru(key)
  @store[key]
end

#[]=(key, value) ⇒ Object



12
13
14
15
16
# File 'lib/i18n/backend/http/lru_cache.rb', line 12

def []=(key, value)
  @store[key] = value
  set_lru(key)
  @store.delete(@lru.pop) if @lru.size > @size
end

#keysObject



23
24
25
# File 'lib/i18n/backend/http/lru_cache.rb', line 23

def keys
  @store.keys
end

#valuesObject



27
28
29
# File 'lib/i18n/backend/http/lru_cache.rb', line 27

def values
  @store.values
end