Class: VitalsImage::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vitals_image/cache.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



9
10
11
# File 'lib/vitals_image/cache.rb', line 9

def initialize
  @store = ActiveSupport::Cache::MemoryStore.new
end

Instance Method Details

#locate(key) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# 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