Skip to content

Commit e04746d

Browse files
authored
Merge pull request #1524 from sul-dlss/info-cache
Cache the json response for 5 minutes
2 parents 879482f + c90da0e commit e04746d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/services/iiif_metadata_service.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def handle_response(conn)
6666
end
6767

6868
def json
69-
@json ||= begin
69+
@json ||= Rails.cache.fetch(cache_key, expires_in: 5.minutes) do
7070
retrieved_json = retrieve
7171
JSON.parse(retrieved_json).tap do |data|
7272
data['@id'] = @canonical_url
@@ -75,4 +75,8 @@ def json
7575
raise Stacks::UnexpectedMetadataResponseError, "There was a problem fetching #{@url}. #{e}: #{retrieved_json}"
7676
end
7777
end
78+
79+
def cache_key
80+
"iiif_metadata/#{Digest::SHA256.hexdigest(@url)}"
81+
end
7882
end

0 commit comments

Comments
 (0)