Class: YrWeather::RedisCache
- Inherits:
-
Object
- Object
- YrWeather::RedisCache
- Defined in:
- lib/yr_weather.rb
Instance Method Summary collapse
- #from_cache ⇒ Object
-
#initialize(params) ⇒ RedisCache
constructor
A new instance of RedisCache.
- #to_cache(data) ⇒ Object
Constructor Details
#initialize(params) ⇒ RedisCache
31 32 33 34 35 |
# File 'lib/yr_weather.rb', line 31 def initialize(params) @latitude = params[:latitude] @longitude = params[:longitude] @redis = params[:redis] end |
Instance Method Details
#from_cache ⇒ Object
43 44 45 |
# File 'lib/yr_weather.rb', line 43 def from_cache @redis.get(redis_key) end |
#to_cache(data) ⇒ Object
37 38 39 40 41 |
# File 'lib/yr_weather.rb', line 37 def to_cache(data) seconds_to_cache = (data[:expires] - Time.now).ceil seconds_to_cache = 60 if seconds_to_cache < 60 @redis.set(redis_key, data.to_json, ex: seconds_to_cache) end |