Sha256: 15527a09417ce697788871b2e097fe4e53ac3cb3ef4355bc234b6141dfd9f332

Contents?: true

Size: 1.67 KB

Versions: 17

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true
require 'sprockets/base'

module Sprockets
  # `CachedEnvironment` is a special cached version of `Environment`.
  #
  # The expection is that all of its file system methods are cached
  # for the instances lifetime. This makes `CachedEnvironment` much faster. This
  # behavior is ideal in production environments where the file system
  # is immutable.
  #
  # `CachedEnvironment` should not be initialized directly. Instead use
  # `Environment#cached`.
  class CachedEnvironment < Base
    def initialize(environment)
      initialize_configuration(environment)

      @cache   = environment.cache
      @stats   = {}
      @entries = {}
      @uris    = {}
      @processor_cache_keys = {}
      @resolved_dependencies = {}
    end

    # No-op return self as cached environment.
    def cached
      self
    end
    alias_method :index, :cached

    # Internal: Cache Environment#entries
    def entries(path)
      @entries[path] ||= super(path)
    end

    # Internal: Cache Environment#stat
    def stat(path)
      @stats[path] ||= super(path)
    end

    # Internal: Cache Environment#load
    def load(uri)
      @uris[uri] ||= super(uri)
    end

    # Internal: Cache Environment#processor_cache_key
    def processor_cache_key(str)
      @processor_cache_keys[str] ||= super(str)
    end

    # Internal: Cache Environment#resolve_dependency
    def resolve_dependency(str)
      @resolved_dependencies[str] ||= super(str)
    end

    private
      # Cache is immutable, any methods that try to change the runtime config
      # should bomb.
      def config=(config)
        raise RuntimeError, "can't modify immutable cached environment"
      end
  end
end

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/cached_environment.rb
sprockets-4.0.2 lib/sprockets/cached_environment.rb
sprockets-4.0.1 lib/sprockets/cached_environment.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb
sprockets-4.0.0 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta10 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta9 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta8 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta7 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta6 lib/sprockets/cached_environment.rb
sprockets-4.0.0.beta5 lib/sprockets/cached_environment.rb