Module: Retriever::Config

Defined in:
lib/retriever/config.rb

Overview

Configuration Namespace

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.encryptObject

Boolean value to indicate whether or not key used for cache is encrypted or not.



6
7
8
# File 'lib/retriever/config.rb', line 6

def encrypt
  @encrypt
end

Class Method Details

.storage(type) ⇒ Object

Set storage handler to be used by retriever. This is a requirement to be set so that you can use retriever.

Storage Handlers (Built-in)

  • :ephemeral - Uses a ruby hash to store cache.

  • :redis - Use redis. (Requires redis gem.)

Custom Storage Handlers

You can supply your own storage handler. In the class you supply, you need to specify the following methods:

  • set(key, value) - Used to set value in the cache store.

  • get(key) - Used to retrieve value from cache store.

  • delete(key) - Used to delete a record from cache store.

Examples

Retriever.config.storage(:ephemeral) # Set storage to memory.
Retriever.config.storage(:redis)  # Set storage to redis.

class CustomStorageHandler
  def set(key, value)
    ...
  end

  def get(key)
    ...
  end

  def delete(key)
    ...
  end
end

Retriever.config.storage(CustomStorageHandler) # Set storage to a custom storage.


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/retriever/config.rb', line 58

def storage(type)
  if type.is_a? Class
    ::Retriever.storage = type.new if type.is_a?(Class)
  else
    case type
    when :ephemeral
      require File.join(File.dirname(__FILE__), 'storage', 'ephemeral')
      ::Retriever.storage = Retriever::Storage::Ephemeral.new
    when :redis
      require File.join(File.dirname(__FILE__), 'storage', 'redis')
      ::Retriever.storage = Retriever::Storage::Redis.new
    end
  end
end