Skip to content
Snippets Groups Projects
Commit c2c34aa4 authored by Kasper Weibel's avatar Kasper Weibel
Browse files

Rename files and add comments

parent a0eaaa13
No related branches found
No related tags found
No related merge requests found
# This class implements a common cache interface with simple delegation to the chosen cache store.
require 'dalli_client'
require 'redis_client'
class AutoexpireCache
def initialize(store_type = :redis, ttl = 86400)
@store = case store_type
when :redis
RedisClient.new(ttl)
when :dalli
DalliClient.new(ttl)
else
raise 'Unknown client type'
end
end
def [](url)
@store.[](url)
end
def []=(url, value)
@store.[]=(url, value)
end
def keys
@store.keys
end
def del(url)
@store.del(url)
end
end
Geocoder.configure(:cache => AutoexpireCache.new)
# This class implements a cache with simple delegation to the the Dalli Memcached client
# https://github.com/mperham/dalli
#
# A TTL is set on initialization
# Dalli is set up as on Heroku using the Memcachier gem.
# https://devcenter.heroku.com/articles/memcachier#ruby
# On other setups you might have to specify your Memcached server in Dalli::Client.new
require 'dalli/client' require 'dalli/client'
require 'yaml' require 'yaml'
class DalliClient class AutoexpireCacheDalli
# Setup Dalli as on Heroku using the Memcachier gem.
# On other setups you'll have to specify your Memcached server
def initialize(ttl = 86400) def initialize(ttl = 86400)
@keys = 'GeocoderDalliClientKeys' @keys = 'GeocoderDalliClientKeys'
@store = Dalli::Client.new(:expires_in => ttl) @store = Dalli::Client.new(:expires_in => ttl)
......
# This class implements a cache with simple delegation to the Redis store, but # 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. # 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. # It should be fairly simple to do the same thing with Memcached.
class RedisClient class AutoexpireCacheRedis
def initialize(ttl = 86400) def initialize(ttl = 86400)
@store = Redis.new @store = Redis.new
@ttl = ttl @ttl = ttl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment