A meta-cache that chains multiple caches together. Specifically:
All `#store`s are passed to all caches.
`#retrieve`s are passed to each cache until one has a hit.
When one cache has a hit, the value is `#store`d in all earlier caches.
Create a new cache chaining the given caches.
@param caches [Array<Sass::CacheStores::Base>] The caches to chain.
# File lib/sass/cache_stores/chain.rb, line 13 def initialize(*caches) @caches = caches end
@see Sass::CacheStores::Base#retrieve
# File lib/sass/cache_stores/chain.rb, line 23 def retrieve(key, sha) @caches.each_with_index do |c, i| obj = c.retrieve(key, sha) next unless obj @caches[0...i].each {|prev| prev.store(key, sha, obj)} return obj end nil end
@see Sass::CacheStores::Base#store
# File lib/sass/cache_stores/chain.rb, line 18 def store(key, sha, obj) @caches.each {|c| c.store(key, sha, obj)} end