Class: SolidQueueMonitor::AssetCache

Inherits:
Object
  • Object
show all
Defined in:
app/services/solid_queue_monitor/asset_cache.rb

Constant Summary collapse

ASSET_ROOT =
SolidQueueMonitor::Engine.root.join('app/assets').freeze
SUBDIRS_BY_EXT =
{ '.css' => 'stylesheets', '.js' => 'javascripts' }.freeze
MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.clear!Object



38
39
40
# File 'app/services/solid_queue_monitor/asset_cache.rb', line 38

def clear!
  MUTEX.synchronize { @entries = {} }
end

.fetch_by_name(file_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/solid_queue_monitor/asset_cache.rb', line 14

def fetch_by_name(file_name)
  path = path_for(file_name)
  return nil unless path&.file?

  cached = @entries[path.to_s]
  return cached if cached && cached[:mtime] == path.mtime

  MUTEX.synchronize do
    cached = @entries[path.to_s]
    return cached if cached && cached[:mtime] == path.mtime

    content = path.read
    @entries[path.to_s] = {
      content: content,
      mtime: path.mtime,
      etag: Digest::SHA256.hexdigest(content)[0, 16]
    }
  end
end

.fingerprint_for(file_name) ⇒ Object



34
35
36
# File 'app/services/solid_queue_monitor/asset_cache.rb', line 34

def fingerprint_for(file_name)
  fetch_by_name(file_name)&.dig(:etag)
end