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

Pass cache store object on init

parent c2c34aa4
No related branches found
No related tags found
No related merge requests found
......@@ -2,17 +2,12 @@
# 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 'yaml'
class AutoexpireCacheDalli
def initialize(ttl = 86400)
def initialize(store, ttl = 86400)
@store = store
@keys = 'GeocoderDalliClientKeys'
@store = Dalli::Client.new(:expires_in => ttl)
@ttl = ttl
end
def [](url)
......@@ -25,7 +20,7 @@ class AutoexpireCacheDalli
if value.nil?
del(url)
else
key_cache_add(url) if @store.add(key, YAML::dump(value))
key_cache_add(url) if @store.add(key, YAML::dump(value), @ttl)
end
value
end
......@@ -60,3 +55,8 @@ class AutoexpireCacheDalli
@store.replace(@keys, YAML::dump(tmp))
end
end
# Here 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
Geocoder.configure(:cache => AutoexpireCacheDalli.new(Dalli::Client.new))
......@@ -2,8 +2,8 @@
# 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 AutoexpireCacheRedis
def initialize(ttl = 86400)
@store = Redis.new
def initialize(store, ttl = 86400)
@store = store
@ttl = ttl
end
......@@ -23,4 +23,6 @@ class AutoexpireCacheRedis
def del(url)
@store.del(url)
end
end
\ No newline at end of file
end
Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new))
\ No newline at end of file
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