Class: Sass::CacheStores::Chain
- Inherits:
-
Base
- Object
- Base
- Sass::CacheStores::Chain
- Defined in:
- .ruby-sass/lib/sass/cache_stores/chain.rb
Overview
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.
Instance Method Summary (collapse)
-
#initialize(*caches) ⇒ Chain
constructor
Create a new cache chaining the given caches.
- #retrieve(key, sha) ⇒ Object
- #store(key, sha, obj) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*caches) ⇒ Chain
Create a new cache chaining the given caches.
13 14 15 |
# File '.ruby-sass/lib/sass/cache_stores/chain.rb', line 13 def initialize(*caches) @caches = caches end |
Constructor Details
#initialize(*caches) ⇒ Chain
Create a new cache chaining the given caches.
13 14 15 |
# File '.ruby-sass/lib/sass/cache_stores/chain.rb', line 13 def initialize(*caches) @caches = caches end |
Instance Method Details
#retrieve(key, sha) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File '.ruby-sass/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 |
#store(key, sha, obj) ⇒ Object
18 19 20 |
# File '.ruby-sass/lib/sass/cache_stores/chain.rb', line 18 def store(key, sha, obj) @caches.each {|c| c.store(key, sha, obj)} end |