module CacheHelper
  def load_cache(path, expire=4.hours)
    data = $redis.get(path)
    if data.nil?
      data = yield
      $redis.set(path, data)
      $redis.expire(path, expire) if expire
    end
    parsed_data = JSON.parse(data)
    return parsed_data if parsed_data.is_a?(Array)

    # Allow for hash to use string and symbol
    # i.e response['key'] or response[:key]
    ActiveSupport::HashWithIndifferentAccess.new(parsed_data)
  rescue
  end
end
