5.4 enabled caching in dev environment

This commit is contained in:
Aaro Koivukangas
2023-11-16 15:07:51 +02:00
parent 9fa96d8456
commit 726ecd3e2b
3 changed files with 8 additions and 4 deletions
+2 -2
View File
@@ -23,14 +23,14 @@ Rails.application.configure do
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.cache_store = :file_store, "tmp/cache_store"
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
config.cache_store = :file_store, "tmp/cache_store"
end
# Store uploaded files on the local file system (see config/storage.yml for options).
+1 -1
View File
@@ -25,7 +25,7 @@ Rails.application.configure do
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
config.cache_store = :memory_store
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
+5 -1
View File
@@ -1,10 +1,14 @@
class BeermappingApi
def self.places_in(city)
city = city.downcase
Rails.cache.fetch(city, expires_in: 1.week) { get_places_in city }
end
def self.get_places_in(city)
url = "http://beermapping.com/webservice/loccity/#{key}/"
response = HTTParty.get "#{url}#{ERB::Util.url_encode(city)}"
places = response.parsed_response["bmp_locations"]["location"]
return [] if places.is_a?(Hash) && places["id"].nil?
places = [places] if places.is_a?(Hash)