Sha256: e9937d7672f6c9e86ea02d9d3e4e59d9695f68b67cf37af53ec44aaae30c335f

Contents?: true

Size: 953 Bytes

Versions: 137

Compression:

Stored size: 953 Bytes

Contents

module Sass
  module CacheStores
    # 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.
    class Chain < Base
      # Create a new cache chaining the given caches.
      #
      # @param caches [Array<Sass::CacheStores::Base>] The caches to chain.
      def initialize(*caches)
        @caches = caches
      end

      # @see Base#store
      def store(key, sha, obj)
        @caches.each {|c| c.store(key, sha, obj)}
      end

      # @see Base#retrieve
      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
    end
  end
end

Version data entries

137 entries across 134 versions & 9 rubygems

Version Path
sass-3.4.7 lib/sass/cache_stores/chain.rb
sass-3.4.6 lib/sass/cache_stores/chain.rb
sass-3.4.5 lib/sass/cache_stores/chain.rb
sass-3.4.4 lib/sass/cache_stores/chain.rb
sass-3.4.3 lib/sass/cache_stores/chain.rb
sass-3.4.2 lib/sass/cache_stores/chain.rb
sass-3.4.1 lib/sass/cache_stores/chain.rb
oreorenasass-3.4.4 lib/sass/cache_stores/chain.rb
oreorenasass-3.4.3 lib/sass/cache_stores/chain.rb
oreorenasass-3.4.2 lib/sass/cache_stores/chain.rb
oreorenasass-3.4.1 lib/sass/cache_stores/chain.rb
oreorenasass-3.4.0 lib/sass/cache_stores/chain.rb
sass-3.4.0 lib/sass/cache_stores/chain.rb
sass-3.4.0.rc.3 lib/sass/cache_stores/chain.rb
sass-3.3.14 lib/sass/cache_stores/chain.rb
sass-3.3.13 lib/sass/cache_stores/chain.rb
sass-3.3.12 lib/sass/cache_stores/chain.rb
sass-3.4.0.rc.2 lib/sass/cache_stores/chain.rb
sass-3.3.11 lib/sass/cache_stores/chain.rb
sass-3.4.0.rc.1 lib/sass/cache_stores/chain.rb