Class: BuildpackSupport::Cache::CachedFile
- Inherits:
-
Object
- Object
- BuildpackSupport::Cache::CachedFile
- Defined in:
- lib/buildpack_support/cache/cached_file.rb
Overview
Represents a file cached on a filesystem
Note: this class is thread-safe, however access to the cached files is not
Instance Method Summary collapse
-
#cached(mode_enc, *additional_args) {|file, additional_args| ... } ⇒ Void
Opens the cached file.
-
#cached? ⇒ Boolean
Returns whether or not data is cached.
-
#destroy ⇒ Object
Destroys the cached file.
-
#etag(mode_enc, *additional_args) {|file| ... } ⇒ Void
Opens the etag file.
-
#etag? ⇒ Boolean
Returns whether or not an etag is stored.
-
#initialize(cache_root, uri, mutable) ⇒ CachedFile
constructor
Creates an instance of the cached file.
-
#last_modified(mode_enc, *additional_args) {|file| ... } ⇒ Void
Opens the last modified file.
-
#last_modified? ⇒ Boolean
Returns whether or not a last modified time stamp is stored.
Constructor Details
#initialize(cache_root, uri, mutable) ⇒ CachedFile
Creates an instance of the cached file. Files created and expected by this class will all be rooted at cache_root
.
33 34 35 36 37 38 39 40 41 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 33 def initialize(cache_root, uri, mutable) key = URI.escape(uri, ':/') @cached = cache_root + "#{key}.cached" @etag = cache_root + "#{key}.etag" @last_modified = cache_root + "#{key}.last_modified" @mutable = mutable FileUtils.mkdir_p cache_root if mutable end |
Instance Method Details
#cached(mode_enc, *additional_args) {|file, additional_args| ... } ⇒ Void
Opens the cached file
50 51 52 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 50 def cached(mode_enc, *additional_args, &block) @cached.open(mode_enc) { |f| block.call f, *additional_args } end |
#cached? ⇒ Boolean
Returns whether or not data is cached.
57 58 59 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 57 def cached? @cached.exist? end |
#destroy ⇒ Object
Destroys the cached file
62 63 64 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 62 def destroy [@cached, @etag, @last_modified].each { |f| f.delete if f.exist? } if @mutable end |
#etag(mode_enc, *additional_args) {|file| ... } ⇒ Void
Opens the etag file
73 74 75 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 73 def etag(mode_enc, *additional_args, &block) @etag.open(mode_enc) { |f| block.call f, *additional_args } end |
#etag? ⇒ Boolean
Returns whether or not an etag is stored.
80 81 82 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 80 def etag? @etag.exist? end |
#last_modified(mode_enc, *additional_args) {|file| ... } ⇒ Void
Opens the last modified file
91 92 93 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 91 def last_modified(mode_enc, *additional_args, &block) @last_modified.open(mode_enc) { |f| block.call f, *additional_args } end |
#last_modified? ⇒ Boolean
Returns whether or not a last modified time stamp is stored.
98 99 100 |
# File 'lib/buildpack_support/cache/cached_file.rb', line 98 def last_modified? @last_modified.exist? end |