Class: YrWeather::RedisCache

Inherits:
Object
  • Object
show all
Defined in:
lib/yr_weather.rb

Instance Method Summary collapse

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_cacheObject



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