Class: Sprockets::CachedEnvironment
- 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
Constants included from PathUtils
Constants included from Utils
Utils::UNBOUND_METHODS_BIND_TO_ANY_OBJECT
Constants included from DigestUtils
DigestUtils::DIGEST_SIZES, DigestUtils::NI_HASH_ALGORITHMS
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Configuration
#computed_config, #config, #context_class, #logger
Instance Method Summary collapse
-
#_entries ⇒ Object
Internal: Cache Environment#entries.
-
#_load ⇒ Object
Internal: Cache Environment#load.
-
#_processor_cache_key ⇒ Object
Internal: Cache Environment#processor_cache_key.
-
#_resolve_dependency ⇒ Object
Internal: Cache Environment#resolve_dependency.
-
#_stat ⇒ Object
Internal: Cache Environment#stat.
-
#cached ⇒ Object
(also: #index)
No-op return self as cached environment.
- #entries(path) ⇒ Object
-
#initialize(environment) ⇒ CachedEnvironment
constructor
A new instance of CachedEnvironment.
- #load(uri) ⇒ Object
- #processor_cache_key(str) ⇒ Object
- #resolve_dependency(str) ⇒ Object
- #stat(path) ⇒ Object
Methods inherited from Base
#[], #cache_get, #cache_set, #each_logical_path, #file_digest, #find_all_linked_assets, #find_asset, #inspect, #logical_paths, #resolve_with_compat
Methods included from Bower
#read_bower_main, #resolve_alternates
Methods included from 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, #file_digest_dependency_set, #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_upwards, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat_directory, #stat_sorted_tree, #stat_tree
Methods included from Engines
#engine_mime_types, #engines, #register_engine
Methods included from Utils
#concat_javascript_sources, #dfs, #dfs_paths, #duplicable?, #hash_reassoc, #hash_reassoc1, #module_include, #normalize_extension, #string_end_with_semicolon?
Methods included from Mime
#mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #register_mime_type
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
Methods included from Transformers
#compose_transformers, #expand_transform_accepts, #register_transformer, #resolve_transform_type, #transformers
Methods included from DigestUtils
#detect_digest_class, #digest, #digest_class, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest
Methods included from Server
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 Dependencies
#add_dependency, #dependencies, #dependency_resolvers, #register_dependency_resolver, #resolve_dependencies
Methods included from PathDigestUtils
#file_digest, #files_digest, #stat_digest
Constructor Details
#initialize(environment) ⇒ CachedEnvironment
Returns a new instance of CachedEnvironment.
14 15 16 17 18 19 20 21 22 23 24 |
# 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) } @uris = Hash.new { |h, k| h[k] = _load(k) } @processor_cache_keys = Hash.new { |h, k| h[k] = _processor_cache_key(k) } @resolved_dependencies = Hash.new { |h, k| h[k] = _resolve_dependency(k) } end |
Instance Method Details
#_entries ⇒ Object
Internal: Cache Environment#entries
33 |
# File 'lib/sprockets/cached_environment.rb', line 33 alias_method :_entries, :entries |
#_load ⇒ Object
Internal: Cache Environment#load
45 |
# File 'lib/sprockets/cached_environment.rb', line 45 alias_method :_load, :load |
#_processor_cache_key ⇒ Object
Internal: Cache Environment#processor_cache_key
51 |
# File 'lib/sprockets/cached_environment.rb', line 51 alias_method :_processor_cache_key, :processor_cache_key |
#_resolve_dependency ⇒ Object
Internal: Cache Environment#resolve_dependency
57 |
# File 'lib/sprockets/cached_environment.rb', line 57 alias_method :_resolve_dependency, :resolve_dependency |
#_stat ⇒ Object
Internal: Cache Environment#stat
39 |
# File 'lib/sprockets/cached_environment.rb', line 39 alias_method :_stat, :stat |
#cached ⇒ Object 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
34 35 36 |
# File 'lib/sprockets/cached_environment.rb', line 34 def entries(path) @entries[path] end |
#load(uri) ⇒ Object
46 47 48 |
# File 'lib/sprockets/cached_environment.rb', line 46 def load(uri) @uris[uri] end |
#processor_cache_key(str) ⇒ Object
52 53 54 |
# File 'lib/sprockets/cached_environment.rb', line 52 def processor_cache_key(str) @processor_cache_keys[str] end |
#resolve_dependency(str) ⇒ Object
58 59 60 |
# File 'lib/sprockets/cached_environment.rb', line 58 def resolve_dependency(str) @resolved_dependencies[str] end |
#stat(path) ⇒ Object
40 41 42 |
# File 'lib/sprockets/cached_environment.rb', line 40 def stat(path) @stats[path] end |