Class: Sprockets::CachedEnvironment

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

Overview

‘CachedEnvironment` is a special cached version of `Environment`.

The exception 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`.

Constant Summary

Constants included from Bower

Bower::POSSIBLE_BOWER_JSONS

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Constants included from ProcessorUtils

ProcessorUtils::VALID_METADATA_COMPOUND_TYPES, ProcessorUtils::VALID_METADATA_COMPOUND_TYPES_HASH, ProcessorUtils::VALID_METADATA_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES_HASH

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::HASH_ALGORITHMS

Constants included from Server

Server::ALLOWED_REQUEST_METHODS, Server::VARY, Server::X_CASCADE

Constants included from SourceMapUtils

SourceMapUtils::BASE64_DIGITS, SourceMapUtils::BASE64_VALUES, SourceMapUtils::VLQ_BASE, SourceMapUtils::VLQ_BASE_MASK, SourceMapUtils::VLQ_BASE_SHIFT, SourceMapUtils::VLQ_CONTINUATION_BIT

Instance Attribute Summary

Attributes inherited from Base

#cache

Attributes included from Configuration

#config, #context_class, #logger

Instance Method Summary collapse

Methods inherited from Base

#[], #compress_from_root, #expand_from_root, #file_digest, #find_all_linked_assets, #find_asset, #find_asset!, #inspect

Methods included from Npm

#read_package_directives, #resolve_alternates

Methods included from Bower

#read_bower_main, #resolve_alternates

Methods included from Resolve

#resolve, #resolve!

Methods included from HTTPUtils

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

Methods included from PathDependencyUtils

#entries_with_dependencies, #stat_directory_with_dependencies, #stat_sorted_tree_with_dependencies

Methods included from URIUtils

#build_asset_uri, #build_file_digest_uri, #encode_uri_query_params, #join_file_uri, #join_uri, #parse_asset_uri, #parse_file_digest_uri, #parse_uri_query_params, #split_file_uri, #split_uri, #valid_asset_uri?

Methods included from PathUtils

#absolute_path?, #atomic_write, #directory?, #file?, #find_matching_path_for_extensions, #find_upwards, #join, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #relative_path_from, #set_pipeline, #split_subpath, #stat_directory, #stat_sorted_tree, #stat_tree

Methods included from Mime

#mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #register_mime_type

Methods included from Utils

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

Methods included from Processing

#bundle_processors, #pipelines, #postprocessors, #preprocessors, #register_bundle_metadata_reducer, #register_bundle_processor, #register_pipeline, #register_postprocessor, #register_preprocessor, #unregister_bundle_processor, #unregister_postprocessor, #unregister_preprocessor

Methods included from ProcessorUtils

#call_processor, #call_processors, #compose_processors, #processors_cache_keys, #validate_processor_result!

Methods included from Transformers

#compose_transformers, #expand_transform_accepts, #register_transformer, #register_transformer_suffix, #resolve_transform_type, #transformers

Methods included from DigestUtils

#already_digested?, #detect_digest_class, #digest, #digest_class, #hexdigest, #hexdigest_integrity_uri, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest, #unpack_hexdigest

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 Exporting

#export_concurrent, #export_concurrent=, #exporters, #register_exporter, #unregister_exporter

Methods included from Compressing

#compressors, #css_compressor, #css_compressor=, #gzip=, #gzip?, #js_compressor, #js_compressor=, #register_compressor, #skip_gzip?

Methods included from Dependencies

#add_dependency, #dependencies, #dependency_resolvers, #register_dependency_resolver

Methods included from PathDigestUtils

#file_digest, #files_digest, #stat_digest

Methods included from SourceMapUtils

#bsearch_mappings, #combine_source_maps, #compare_source_offsets, #concat_source_maps, #decode_source_map, #decode_vlq_mappings, #encode_source_map, #encode_vlq_mappings, #format_source_map, #make_index_map, #vlq_decode, #vlq_decode_mappings, #vlq_encode, #vlq_encode_mappings

Constructor Details

#initialize(environment) ⇒ CachedEnvironment

Returns a new instance of CachedEnvironment.



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

def initialize(environment)
  initialize_configuration(environment)

  @cache   = environment.cache
  @stats   = Concurrent::Map.new
  @entries = Concurrent::Map.new
  @uris    = Concurrent::Map.new
  @processor_cache_keys = Concurrent::Map.new
  @resolved_dependencies = Concurrent::Map.new
end

Instance Method Details

#cachedObject Also known as: index

No-op return self as cached environment.



27
28
29
# File 'lib/sprockets/cached_environment.rb', line 27

def cached
  self
end

#entries(path) ⇒ Object

Internal: Cache Environment#entries



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

def entries(path)
  @entries.fetch_or_store(path) { super(path) }
end

#load(uri) ⇒ Object

Internal: Cache Environment#load



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

def load(uri)
  @uris.fetch_or_store(uri) { super(uri) }
end

#processor_cache_key(str) ⇒ Object

Internal: Cache Environment#processor_cache_key



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

def processor_cache_key(str)
  @processor_cache_keys.fetch_or_store(str) { super(str) }
end

#resolve_dependency(str) ⇒ Object

Internal: Cache Environment#resolve_dependency



53
54
55
# File 'lib/sprockets/cached_environment.rb', line 53

def resolve_dependency(str)
  @resolved_dependencies.fetch_or_store(str) { super(str) }
end

#stat(path) ⇒ Object

Internal: Cache Environment#stat



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

def stat(path)
  @stats.fetch_or_store(path) { super(path) }
end