Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
module Marketing
module Teacher
class PromotionsController < ApplicationController
PROMOTIONS_CONTENTFUL_CONTENT_TYPE = 'teacher-homepage-sidebar'
CACHE_EXPIRATION = 1.hour

# GET /marketing/teacher/promotions/:id
# Returns a teacher sidebar with up to two individual promotional items.
def show
entry = CdoContentful::Marketing::Entry::TeacherHomepageSidebar.find(params[:id])
entry = cached_contentful_promotions(params[:id])
return head :not_found unless entry

result = entry.fields.clone
Expand All @@ -20,6 +23,12 @@ def show
rescue ArgumentError => exception
render json: {error: exception.message}, status: :bad_request
end

private def cached_contentful_promotions(id)
CDO.shared_cache.fetch("contentful-#{PROMOTIONS_CONTENTFUL_CONTENT_TYPE}:#{id}", expires_in: CACHE_EXPIRATION) do
CdoContentful::Marketing::Entry::TeacherHomepageSidebar.find(id)
end
end
end
end
end