Sha256: 6475299111ca5d11c7dba63fb538035854bacb0573ea890cdabc78cfa908c735

Contents?: true

Size: 602 Bytes

Versions: 2

Compression:

Stored size: 602 Bytes

Contents

# This class implements a cache with simple delegation to the Redis store, but
# when it creates a key/value pair, it also sends an EXPIRE command with a TTL.
# It should be fairly simple to do the same thing with Memcached.
class AutoexpireCache
  def initialize(store)
    @store = store
    @ttl = 86400
  end

  def [](url)
    @store.[](url)
  end

  def []=(url, value)
    @store.[]=(url, value)
    @store.expire(url, @ttl)
  end

  def keys
    @store.keys
  end

  def del(url)
    @store.del(url)
  end
end

Geocoder.configure do |config|
  config.cache = AutoexpireCache.new(Redis.new)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geocoder-1.1.5 examples/autoexpire_cache.rb
geocoder-1.1.4 examples/autoexpire_cache.rb