class Geocoder::Cache
def [](url)
Read from the Cache.
#
def [](url) interpret store_service.read(url) rescue => e Geocoder.log(:warn, "Geocoder cache read error: #{e}") end
def []=(url, value)
Write to the Cache.
#
def []=(url, value) store_service.write(url, value) rescue => e Geocoder.log(:warn, "Geocoder cache write error: #{e}") end
def expire(url)
or pass :all to clear all URLs.
Delete cache entry for given URL,
#
def expire(url) if url == :all if store_service.respond_to?(:keys) urls.each{ |u| expire(u) } else raise(NoMethodError, "The Geocoder cache store must implement `#keys` for `expire(:all)` to work") end else expire_single_url(url) end end
def expire_single_url(url)
def expire_single_url(url) store_service.remove(url) end
def initialize(store, config)
def initialize(store, config) @class = (Geocoder::CacheStore.const_get("#{store.class}", false) rescue Geocoder::CacheStore::Generic) @store_service = @class.new(store, config) end
def interpret(value)
(Some key/value stores return empty string instead of nil.)
Clean up value before returning. Namely, convert empty string to nil.
#
def interpret(value) value == "" ? nil : value end
def keys
that have non-nil values.
Array of keys with the currently configured prefix
#
def keys store_service.keys end
def store_service; @store_service; end
def store_service; @store_service; end
def urls
Array of cached URLs.
#
def urls store_service.urls end