Class: DnsOne::Cache
Constant Summary collapse
- DEFAULT_MAX_SIZE =
100000
Instance Method Summary collapse
- #add(k, v) ⇒ Object
- #find(k) ⇒ Object
-
#initialize(max_size = nil) ⇒ Cache
constructor
A new instance of Cache.
- #stat ⇒ Object
Constructor Details
#initialize(max_size = nil) ⇒ Cache
Returns a new instance of Cache.
5 6 7 8 |
# File 'lib/dns_one/cache.rb', line 5 def initialize max_size = nil @max_size = max_size || DEFAULT_MAX_SIZE @cache = {} end |
Instance Method Details
#add(k, v) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/dns_one/cache.rb', line 10 def add k, v @cache[k] = v if @cache.length > @max_size @cache.delete @cache.keys.first end v end |
#find(k) ⇒ Object
18 19 20 |
# File 'lib/dns_one/cache.rb', line 18 def find k @cache[k] end |
#stat ⇒ Object
22 23 24 |
# File 'lib/dns_one/cache.rb', line 22 def stat "#{@cache.length}/#{@max_size}" end |