Module: Sprockets::Caching

Included in:
Base
Defined in:
lib/sprockets/caching.rb

Overview

‘Caching` is an internal mixin whose public methods are exposed on the `Environment` and `Index` classes.

Instance Method Summary collapse

Instance Method Details

#asset_from_hash(hash) ⇒ Object

Return ‘Asset` instance for serialized `Hash`.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sprockets/caching.rb', line 9

def asset_from_hash(hash)
  return unless hash.is_a?(Hash)
  case hash['class']
  when 'BundledAsset'
    BundledAsset.from_hash(self, hash)
  when 'StaticAsset'
    StaticAsset.from_hash(self, hash)
  else
    nil
  end
rescue Exception => e
  logger.debug "Cache for Asset (#{hash['logical_path']}) is stale"
  logger.debug e
  nil
end

#cache_hash(key, version) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/sprockets/caching.rb', line 25

def cache_hash(key, version)
  if cache.nil?
    yield
  elsif hash = cache_get_hash(key, version)
    hash
  elsif hash = yield
    cache_set_hash(key, version, hash)
    hash
  end
end