Class: Middleman::CachingProxy::Cache

Inherits:
Object
  • Object
show all
Includes:
Autostruct::Wrap
Defined in:
lib/middleman/caching_proxy/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:, key:) ⇒ Cache

Returns a new instance of Cache.



8
9
10
# File 'lib/middleman/caching_proxy/cache.rb', line 8

def initialize(path:, key:)
  @manifest = nil
end

Instance Method Details

#add(item:, source:) ⇒ Object



19
20
21
22
23
# File 'lib/middleman/caching_proxy/cache.rb', line 19

def add(item:, source:)
  manifest.add item
  cached_path = full_path(item: item)
  copy_in source, cached_path
end

#full_path(item:) ⇒ Object



25
26
27
# File 'lib/middleman/caching_proxy/cache.rb', line 25

def full_path(item:)
  File.join(path, "items", item.path)
end

#has?(item) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/middleman/caching_proxy/cache.rb', line 13

def has?(item)
  cached_path = full_path(item: item)
  return false if !File.exist?(cached_path)
  manifest.has?(item)
end

#saveObject



29
30
31
# File 'lib/middleman/caching_proxy/cache.rb', line 29

def save
  manifest.save
end