module EveBadger::Cache

A wrapper around a Moneta object that provides automatic request caching for Evebadger::EveAPI while enabled.

Public Class Methods

disable() click to toggle source

disable request caching

# File lib/eve_badger/cache.rb, line 22
def self.disable
  @cache = nil
end
enable(*args, **kwargs) click to toggle source

Enable the cache with a specified Moneta adapter. See Moneta API documentation for possible configurations: www.rubydoc.info/gems/moneta/frames

# File lib/eve_badger/cache.rb, line 14
def self.enable(*args, **kwargs)
  unless @native_expires.any? { |name| args.include?(name) }
    kwargs.merge!({expires: true})
  end
  @cache = Moneta.new(*args, **kwargs)
end
enabled?() click to toggle source

test whether request caching is enabled

# File lib/eve_badger/cache.rb, line 27
def self.enabled?
  @cache ? true : false
end
get(key) click to toggle source

retrieve a value from the cache it if is enabled

# File lib/eve_badger/cache.rb, line 46
def self.get(key)
  if @cache
    @cache[key]
  else
    raise "Cannot get when cache is disabled."
  end
end
store(key, value, options={}) click to toggle source

store a value in the cache if it is enabled

# File lib/eve_badger/cache.rb, line 37
def self.store(key, value, options={})
  if @cache
    @cache.store(key, value, options)
  else
    raise "Cannot store when cache is disabled."
  end
end
type() click to toggle source

return the class type of the enabled cache, caches adapters which don’t natively support expiration will all appear as Moneta::Expires

# File lib/eve_badger/cache.rb, line 32
def self.type
  @cache.class
end