Skip to content

Commit

Permalink
[CACHE] GET Event and Location
Browse files Browse the repository at this point in the history
  • Loading branch information
Daivasmara committed May 31, 2023
1 parent 6118d7a commit 03955a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class EventsController < ApiController
load_and_authorize_resource

def show
render json: serialized_event
render json: serialized_event if stale?(@event)
end

def create
Expand Down
4 changes: 3 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def calculate_midpoint_location!
private

def get_location(latitude:, longitude:)
Location.find_or_initialize_by(latitude:, longitude:)
Rails.cache.fetch("location-#{latitude}-#{longitude}", expires_in: 2.days) do
Location.find_or_initialize_by(latitude:, longitude:)
end
end
end

0 comments on commit 03955a0

Please sign in to comment.