class YrWeather::RedisCache

Public Class Methods

new(params) click to toggle source
# File lib/yr_weather.rb, line 31
def initialize(params)
  @latitude  = params[:latitude]
  @longitude = params[:longitude]
  @redis     = params[:redis]
end

Public Instance Methods

from_cache() click to toggle source
# File lib/yr_weather.rb, line 43
def from_cache
  @redis.get(redis_key)
end
to_cache(data) click to toggle source
# 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

Private Instance Methods

redis_key() click to toggle source
# File lib/yr_weather.rb, line 49
def redis_key
  "yr_weather.#{@latitude}.#{@longitude}"
end