Class: IPinfo::DefaultCache

Inherits:
CacheInterface show all
Defined in:
lib/ipinfo/cache/default_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(ttl, max_size) ⇒ DefaultCache

Returns a new instance of DefaultCache.



7
8
9
# File 'lib/ipinfo/cache/default_cache.rb', line 7

def initialize(ttl, max_size)
  @cache = LRUCache.new(:ttl => ttl, :max_size => max_size)
end

Instance Method Details

#contains?(key) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ipinfo/cache/default_cache.rb', line 19

def contains?(key)
  !@cache[key].nil?
end

#get(key) ⇒ Object



11
12
13
# File 'lib/ipinfo/cache/default_cache.rb', line 11

def get(key)
  @cache[key]
end

#set(key, value) ⇒ Object



15
16
17
# File 'lib/ipinfo/cache/default_cache.rb', line 15

def set(key, value)
  @cache[key] = value
end