class VitalsImage::Cache
Public Class Methods
new()
click to toggle source
# File lib/vitals_image/cache.rb, line 9 def initialize @store = ActiveSupport::Cache::MemoryStore.new end
Public Instance Methods
locate(key)
click to toggle source
# File lib/vitals_image/cache.rb, line 13 def locate(key) with_retry do source = @store.read(key) if source.blank? source = find_or_create_by(key) expires_in = source.analyzed ? nil : 1.minute @store.write(key, source, expires_in: expires_in) end source end end
Private Instance Methods
find_or_create_by(key)
click to toggle source
# File lib/vitals_image/cache.rb, line 28 def find_or_create_by(key) uri = URI.parse(key) if VitalsImage.domains.present? && !VitalsImage.domains.include?(uri.host) Source.new(key: key, metadata: { identified: false }) else Source.find_or_create_by(key: key) { |source| source.identified = true } end end
with_retry() { || ... }
click to toggle source
# File lib/vitals_image/cache.rb, line 38 def with_retry yield rescue ActiveRecord::RecordNotUnique yield end