1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
module Geocoder::CacheStore
class Base
def initialize(store, options)
@store = store
@config = options
@prefix = config[:prefix]
end
##
# Array of keys with the currently configured prefix
# that have non-nil values.
def keys
store.keys.select { |k| k.match(/^#{prefix}/) and self[k] }
end
##
# Array of cached URLs.
#
def urls
keys
end
protected # ----------------------------------------------------------------
def prefix; @prefix; end
def store; @store; end
def config; @config; end
##
# Cache key for a given URL.
#
def key_for(url)
if url.match(/^#{prefix}/)
url
else
[prefix, url].join
end
end
end
end
|