Class: Sprockets::CachedEnvironment

Inherits:
Base
  • Object
show all
Defined in:
lib/sprockets/cached_environment.rb

Overview

`Cached` 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 `Cached` much faster. This behavior is ideal in production environments where the file system is immutable.

`Cached` should not be initialized directly. Instead use `Environment#cached`.

Constant Summary

Constants included from Bower

Bower::POSSIBLE_BOWER_JSONS

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::NI_HASH_ALGORITHMS

Constants included from Utils

Utils::UNBOUND_METHODS_BIND_TO_ANY_OBJECT

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Instance Attribute Summary

Attributes inherited from Base

#cache

Attributes included from Configuration

#config, #context_class, #logger

Instance Method Summary collapse

Methods inherited from Base

#[], #find_all_linked_assets, #find_asset, #inspect

Methods included from Legacy

#cache_get, #cache_set, #each_logical_path, #logical_paths

Methods included from Bower

#read_bower_main, #resolve_alternates

Methods included from Resolve

#locate, #resolve

Methods included from URIUtils

#build_asset_uri, #parse_asset_uri, #valid_asset_uri?

Methods included from DigestUtils

#detect_digest_class, #digest, #digest_class, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest

Methods included from Engines

#engine_mime_types, #engines, #register_engine, #unwrap_engines

Methods included from Utils

#concat_javascript_sources, #dfs, #duplicable?, #hash_reassoc, #hash_reassoc1, #module_include, #normalize_extension, #string_end_with_semicolon?

Methods included from Mime

#encodings, #mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #register_encoding, #register_mime_type

Methods included from HTTPUtils

#find_best_mime_type_match, #find_best_q_match, #find_mime_type_matches, #find_q_matches, #match_mime_type?, #parse_q_values

Methods included from PathUtils

#absolute_path?, #atomic_write, #file?, #find_upwards, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat_directory, #stat_sorted_tree, #stat_tree

Methods included from Processing

#bundle_processors, #bundle_reducers, #postprocessors, #preprocessors, #process_bundle_reducers, #register_bundle_metadata_reducer, #register_bundle_processor, #register_postprocessor, #register_preprocessor, #unregister_bundle_processor, #unregister_postprocessor, #unregister_preprocessor, #unwrap_bundle_processors, #unwrap_bundle_reducers, #unwrap_postprocessors, #unwrap_preprocessors

Methods included from Transformers

#expand_transform_accepts, #inverted_transformers, #register_transformer, #resolve_transform_type, #transformers, #unwrap_transformer

Methods included from Server

#call

Methods included from Configuration

#digest_class, #digest_class=, #initialize_configuration, #version, #version=

Methods included from Paths

#append_path, #clear_paths, #each_file, #paths, #prepend_path, #root

Methods included from Compressing

#compressors, #css_compressor, #css_compressor=, #js_compressor, #js_compressor=, #register_compressor

Methods included from PathDigestUtils

#files_digest, #stat_digest

Constructor Details

#initialize(environment) ⇒ CachedEnvironment

Returns a new instance of CachedEnvironment



14
15
16
17
18
19
20
21
22
# File 'lib/sprockets/cached_environment.rb', line 14

def initialize(environment)
  initialize_configuration(environment)

  @cache   = environment.cache
  @stats   = Hash.new { |h, k| h[k] = _stat(k) }
  @entries = Hash.new { |h, k| h[k] = _entries(k) }
  @digests = Hash.new { |h, k| h[k] = _file_digest(k) }
  @uris    = Hash.new { |h, k| h[k] = _load(k) }
end

Instance Method Details

#_entriesObject

Internal: Cache Environment#entries



31
# File 'lib/sprockets/cached_environment.rb', line 31

alias_method :_entries, :entries

#_file_digestObject

Internal: Cache Environment#file_digest



43
# File 'lib/sprockets/cached_environment.rb', line 43

alias_method :_file_digest, :file_digest

#_loadObject

Internal: Cache Environment#load



49
# File 'lib/sprockets/cached_environment.rb', line 49

alias_method :_load, :load

#_statObject

Internal: Cache Environment#stat



37
# File 'lib/sprockets/cached_environment.rb', line 37

alias_method :_stat, :stat

#cachedObject Also known as: index

No-op return self as cached environment.



25
26
27
# File 'lib/sprockets/cached_environment.rb', line 25

def cached
  self
end

#entries(path) ⇒ Object



32
33
34
# File 'lib/sprockets/cached_environment.rb', line 32

def entries(path)
  @entries[path]
end

#file_digest(path) ⇒ Object



44
45
46
# File 'lib/sprockets/cached_environment.rb', line 44

def file_digest(path)
  @digests[path]
end

#load(uri) ⇒ Object



50
51
52
# File 'lib/sprockets/cached_environment.rb', line 50

def load(uri)
  @uris[uri]
end

#stat(path) ⇒ Object



38
39
40
# File 'lib/sprockets/cached_environment.rb', line 38

def stat(path)
  @stats[path]
end