Module: HTTParty::Icebox::ClassMethods

Defined in:
lib/tmdb_party/httparty_icebox.rb

Instance Method Summary collapse

Instance Method Details

#cache(options = {}) ⇒ Object

Enable caching and set cache options Returns memoized cache object

Following options are available, default values are in []:

store

Storage mechanism for cached data (memory, filesystem, your own) [memory]

timeout

Cache expiration in seconds [60]

logger

Path to logfile or logger instance [STDOUT]

Any additional options are passed to the Cache constructor

Usage:

# Enable caching in HTTParty, in memory, for 1 minute
cache # Use default values

# Enable caching in HTTParty, on filesystem (/tmp), for 10 minutes
cache :store => 'file', :timeout => 600, :location => '/tmp/'

# Use your own cache store (see AbstractStore class below)
cache :store => 'memcached', :timeout => 600, :server => '192.168.1.1:1001'


58
59
60
61
62
63
# File 'lib/tmdb_party/httparty_icebox.rb', line 58

def cache(options={})
  options[:store]   ||= 'memory'
  options[:timeout] ||= 60
  logger = options[:logger]
  @cache ||= Cache.new( options.delete(:store), options )
end