Sha256: de64758f1909df8b192dd768803004ffbfc50431535d7e34aeb779f3453e7fea
Contents?: true
Size: 729 Bytes
Versions: 13
Compression:
Stored size: 729 Bytes
Contents
# frozen_string_literal: true module Hyrax class LocationService < ::Qa::Authorities::Geonames CACHE_KEY_PREFIX = 'hyrax_geonames_label-v1-' CACHE_EXPIRATION = 1.week def full_label(uri) return if uri.blank? id = extract_id uri Rails.cache.fetch(cache_key(id), expires_in: CACHE_EXPIRATION) do label.call(find(id)) end end private def extract_id(obj) uri = case obj when String URI(obj) when URI obj else raise ArgumentError, "#{obj} is not a valid type" end uri.path.split('/').last end def cache_key(id) "#{CACHE_KEY_PREFIX}#{id}" end end end
Version data entries
13 entries across 13 versions & 1 rubygems