Class: OpenWeatherClient::Caching
- Inherits:
-
Object
- Object
- OpenWeatherClient::Caching
- Defined in:
- lib/open_weather_client/caching.rb,
lib/open_weather_client/caching/memory.rb
Overview
Caching of OpenWeatherMap requests
The entries are cached according to latitude, longitude and time of the request. The time is clamped to the current hour
This is the caching interface and equals a none cache. Get requests raise an error.
Direct Known Subclasses
Defined Under Namespace
Classes: Memory
Instance Method Summary collapse
-
#cache_key(lat, lon, time) ⇒ Object
Calculate the key for storage in the cache.
-
#get(lat:, lon:, time:) ⇒ Hash
Get an entry out of the cache defined by its
lat
,lon
andtime
. -
#store(data:, lat:, lon:, time:) ⇒ Hash
Store the data by its
lat
,lon
andtime
.
Instance Method Details
#cache_key(lat, lon, time) ⇒ Object
Calculate the key for storage in the cache
53 54 55 |
# File 'lib/open_weather_client/caching.rb', line 53 def cache_key(lat, lon, time) "weather:#{lat}:#{lon}:#{time.strftime('%Y-%m-%dT%H')}" end |
#get(lat:, lon:, time:) ⇒ Hash
Get an entry out of the cache defined by its lat
, lon
and time
.
23 24 25 26 27 28 |
# File 'lib/open_weather_client/caching.rb', line 23 def get(lat:, lon:, time:) key = cache_key(lat, lon, time) raise KeyError unless present?(key) caching_get(key) end |
#store(data:, lat:, lon:, time:) ⇒ Hash
Store the data by its lat
, lon
and time
.
39 40 41 42 43 44 45 |
# File 'lib/open_weather_client/caching.rb', line 39 def store(data:, lat:, lon:, time:) key = cache_key(lat, lon, time) caching_store(key, data) data end |