diff --git a/app/models/ruling_weather_setting.rb b/app/models/ruling_weather_setting.rb index 18b4720..27499c0 100644 --- a/app/models/ruling_weather_setting.rb +++ b/app/models/ruling_weather_setting.rb @@ -50,11 +50,17 @@ class RulingWeatherSetting "locationName" => custom_location} timeout_flag = false begin - cahche_model = self.ruling_weather_cache - if cahche_model.nil? - cahche_model = RulingWeatherCache.create(:cache=>{},:ruling_weather_setting=>self) + cache_model = self.ruling_weather_cache + if cache_model.nil? + 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 - cache = cahche_model.cache rescue {} + cache = cache_model.cache rescue {} res = net_http_get_response(URI.parse("#{url}?#{data.to_query}")) content = JSON.parse(res.body) weather_data = get_weather_data(content) rescue {} @@ -132,7 +138,7 @@ class RulingWeatherSetting "wx_svg" => wx_svg, "ws" => ws, "rain" => rain} - cahche_model.update(:cache=>result,:cache_time=>time_now) + cache_model.update(:cache=>result,:cache_time=>time_now) if uvi_text.blank? result["uvi_text"] = I18n.t("ruling_weather.none") end diff --git a/lib/ruling_weather/engine.rb b/lib/ruling_weather/engine.rb index d19cb39..b01539d 100644 --- a/lib/ruling_weather/engine.rb +++ b/lib/ruling_weather/engine.rb @@ -7,6 +7,13 @@ module RulingWeather authorizable widget_methods ["widget"] 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 head_label_i18n 'ruling_weather.ruling_weather', icon_class: "fa fa-sun-o" available_for "users"