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
# 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
end

#cache_hash(key, version) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/sprockets/caching.rb', line 21

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