module HTTParty::DryIce::ClassMethods

Public Instance Methods

cache(cache, options = {}) click to toggle source

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 [nil, silent]

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'
# File lib/dry_ice.rb, line 37
def cache(cache, options = {})
  return @cache = nil unless cache
  raise "cache instance must respond_to #read, #write and #delete" unless cache.respond_to?(:read) && cache.respond_to?(:write) && cache.respond_to?(:delete)
  @cache = IceCache.new(cache, options)
end
get_cache() click to toggle source
# File lib/dry_ice.rb, line 43
def get_cache
  @cache || false
end