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.5.7 lib/sass/cache_stores/chain.rb
brakeman-4.3.1 bundle/ruby/2.5.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-4.3.0 bundle/ruby/2.5.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-4.2.1 bundle/ruby/2.5.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
sass-3.5.6 lib/sass/cache_stores/chain.rb
brakeman-4.2.0 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
sass-3.5.5 lib/sass/cache_stores/chain.rb
brakeman-4.1.1 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
sass-3.5.4 lib/sass/cache_stores/chain.rb
brakeman-4.1.0 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
sass-3.5.3 lib/sass/cache_stores/chain.rb
sass-3.5.2 lib/sass/cache_stores/chain.rb
brakeman-4.0.1 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-4.0.1.pre1 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-4.0.0 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-3.7.2 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/sass-3.4.25/lib/sass/cache_stores/chain.rb
sass-3.5.1 lib/sass/cache_stores/chain.rb
sass-3.5.0 lib/sass/cache_stores/chain.rb
sass-3.4.25 lib/sass/cache_stores/chain.rb