Adjust cache.
This commit is contained in:
parent
3ac3d4c7ef
commit
0495a4af16
|
@ -50,11 +50,17 @@ class RulingWeatherSetting
|
||||||
"locationName" => custom_location}
|
"locationName" => custom_location}
|
||||||
timeout_flag = false
|
timeout_flag = false
|
||||||
begin
|
begin
|
||||||
cahche_model = self.ruling_weather_cache
|
cache_model = self.ruling_weather_cache
|
||||||
if cahche_model.nil?
|
if cache_model.nil?
|
||||||
cahche_model = RulingWeatherCache.create(:cache=>{},:ruling_weather_setting=>self)
|
cache_model = RulingWeatherCache.create(:cache=>{},:ruling_weather_setting=>self)
|
||||||
|
elsif (cache_model.cache_time.to_i / 3600) == (time_now.to_i / 3600) #The same hour
|
||||||
|
result = cache_model.cache
|
||||||
|
if result["uvi_text"].blank?
|
||||||
|
result["uvi_text"] = I18n.t("ruling_weather.none")
|
||||||
|
end
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
cache = cahche_model.cache rescue {}
|
cache = cache_model.cache rescue {}
|
||||||
res = net_http_get_response(URI.parse("#{url}?#{data.to_query}"))
|
res = net_http_get_response(URI.parse("#{url}?#{data.to_query}"))
|
||||||
content = JSON.parse(res.body)
|
content = JSON.parse(res.body)
|
||||||
weather_data = get_weather_data(content) rescue {}
|
weather_data = get_weather_data(content) rescue {}
|
||||||
|
@ -132,7 +138,7 @@ class RulingWeatherSetting
|
||||||
"wx_svg" => wx_svg,
|
"wx_svg" => wx_svg,
|
||||||
"ws" => ws,
|
"ws" => ws,
|
||||||
"rain" => rain}
|
"rain" => rain}
|
||||||
cahche_model.update(:cache=>result,:cache_time=>time_now)
|
cache_model.update(:cache=>result,:cache_time=>time_now)
|
||||||
if uvi_text.blank?
|
if uvi_text.blank?
|
||||||
result["uvi_text"] = I18n.t("ruling_weather.none")
|
result["uvi_text"] = I18n.t("ruling_weather.none")
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,13 @@ module RulingWeather
|
||||||
authorizable
|
authorizable
|
||||||
widget_methods ["widget"]
|
widget_methods ["widget"]
|
||||||
widget_settings [{"override_category_with"=>"ruling_weather_setting","multiselect"=>false,"display_field"=>"location"}]
|
widget_settings [{"override_category_with"=>"ruling_weather_setting","multiselect"=>false,"display_field"=>"location"}]
|
||||||
|
if File.basename($0) != 'rake'
|
||||||
|
begin
|
||||||
|
avoid_page_cache RulingWeatherCache
|
||||||
|
rescue => e
|
||||||
|
puts ["avoid_page_cache", e.to_s]
|
||||||
|
end
|
||||||
|
end
|
||||||
side_bar do
|
side_bar do
|
||||||
head_label_i18n 'ruling_weather.ruling_weather', icon_class: "fa fa-sun-o"
|
head_label_i18n 'ruling_weather.ruling_weather', icon_class: "fa fa-sun-o"
|
||||||
available_for "users"
|
available_for "users"
|
||||||
|
|
Loading…
Reference in New Issue