Class: Vibe::Cache

Inherits:
Object
  • Object
show all
Extended by:
Configuration
Includes:
Error
Defined in:
lib/vibe/cache.rb

Constant Summary collapse

DRIVERS =
['FILE']

Constants included from Configuration

Vibe::Configuration::DEFAULT_API_KEY, Vibe::Configuration::DEFAULT_CACHE, Vibe::Configuration::DEFAULT_CACHE_DRIVER, Vibe::Configuration::DEFAULT_ENDPOINT, Vibe::Configuration::DEFAULT_FORMAT, Vibe::Configuration::DEFAULT_METHOD, Vibe::Configuration::DEFAULT_USER_AGENT, Vibe::Configuration::VALID_CONFIG_KEYS, Vibe::Configuration::VALID_CONNECTION_KEYS, Vibe::Configuration::VALID_OPTIONS_KEYS

Instance Method Summary collapse

Methods included from Configuration

configure, extended, options, reset

Constructor Details

#initialize(options = {}) ⇒ Cache

Returns a new instance of Cache.



9
10
11
12
13
14
15
16
17
18
# File 'lib/vibe/cache.rb', line 9

def initialize(options = {})
  # If invalid cache driver given
  if options.include?(:driver) && !DRIVERS.include?(options[:driver])
    raise ArgumentError, "unkown cache driver: #{options[:driver]}"
  else
    # Load the required cache driver
    require "vibe/cache-drivers/#{options[:driver].downcase}"
    @driver = eval(options[:driver].downcase.capitalize).new
  end
end

Instance Method Details

#get(key = '') ⇒ Driver.get

Get key from cache, proxies into method with same name in driver class

Returns:



24
25
26
# File 'lib/vibe/cache.rb', line 24

def get(key = '')
  @driver.get(key)
end

#put(key = '', data = '') ⇒ Driver.put

Write to cache, proxies into method with same name in driver class

Returns:



32
33
34
# File 'lib/vibe/cache.rb', line 32

def put(key = '', data = '')
  @driver.put(key, data)
end