From 4427ebf0ab5f4c68ed8219ba1ec9a89eb614d1a5 Mon Sep 17 00:00:00 2001 From: Tim Tilberg <ttilberg@gmail.com> Date: Mon, 1 May 2017 09:09:00 -0500 Subject: [PATCH] Update docs, error msg for cache store #keys (#1165) --- README.md | 1 + lib/geocoder/cache.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c4883a2..79f9299a 100644 --- a/README.md +++ b/README.md @@ -896,6 +896,7 @@ This example uses Redis, but the cache store can be any object that supports the * `store#[](key)` or `#get` or `#read` - retrieves a value * `store#[]=(key, value)` or `#set` or `#write` - stores a value * `store#del(url)` - deletes a value +* `store#keys` - (Optional) Returns array of keys. Used if you wish to expire the entire cache (see below). Even a plain Ruby hash will work, though it's not a great choice (cleared out when app is restarted, not shared between app instances, etc). diff --git a/lib/geocoder/cache.rb b/lib/geocoder/cache.rb index fe2794db..defb2561 100644 --- a/lib/geocoder/cache.rb +++ b/lib/geocoder/cache.rb @@ -40,7 +40,11 @@ module Geocoder # def expire(url) if url == :all - urls.each{ |u| expire(u) } + if store.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 -- GitLab