Class: I18n::Backend::Http::LRUCache
- Inherits:
-
Object
- Object
- I18n::Backend::Http::LRUCache
- Defined in:
- lib/i18n/backend/http/lru_cache.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(size = 10) ⇒ LRUCache
constructor
A new instance of LRUCache.
- #keys ⇒ Object
- #values ⇒ Object
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 |
#keys ⇒ Object
23 24 25 |
# File 'lib/i18n/backend/http/lru_cache.rb', line 23 def keys @store.keys end |
#values ⇒ Object
27 28 29 |
# File 'lib/i18n/backend/http/lru_cache.rb', line 27 def values @store.values end |