Sha256: 7b5b4a098186d58c6567a4c16b71597992eeff73e06997fb2b8de6351fe8ba2f

Contents?: true

Size: 714 Bytes

Versions: 11

Compression:

Stored size: 714 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.
# Alternatively, this class could inherit from Redis, which would make most
# of the below methods unnecessary.
class AutoexpireCacheRedis
  def initialize(store, ttl = 86400)
    @store = store
    @ttl = ttl
  end

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

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

  def keys
    @store.keys
  end

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

Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new))

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
geocoder-1.7.2 examples/autoexpire_cache_redis.rb
geocoder-1.7.1 examples/autoexpire_cache_redis.rb
geocoder-1.7.0 examples/autoexpire_cache_redis.rb
geocoder-1.6.7 examples/autoexpire_cache_redis.rb
geocoder-1.6.6 examples/autoexpire_cache_redis.rb
geocoder-1.6.5 examples/autoexpire_cache_redis.rb
geocoder-1.6.4 examples/autoexpire_cache_redis.rb
geocoder-1.6.3 examples/autoexpire_cache_redis.rb
geocoder-1.6.2 examples/autoexpire_cache_redis.rb
geocoder-1.6.1 examples/autoexpire_cache_redis.rb
geocoder-1.6.0 examples/autoexpire_cache_redis.rb