Class: I18n::Tasks::Scanners::Files::CachingFileReader
- Inherits:
-
FileReader
- Object
- FileReader
- I18n::Tasks::Scanners::Files::CachingFileReader
- Defined in:
- lib/i18n/tasks/scanners/files/caching_file_reader.rb
Overview
Note:
This class is thread-safe. All methods are cached.
Reads the files in ‘rb’ mode and UTF-8 encoding. Wraps a FileReader and caches the results.
Instance Method Summary collapse
-
#initialize ⇒ CachingFileReader
constructor
A new instance of CachingFileReader.
-
#read_file(path) ⇒ String
Return the contents of the file at the given path.
Constructor Details
#initialize ⇒ CachingFileReader
Returns a new instance of CachingFileReader.
13 14 15 16 |
# File 'lib/i18n/tasks/scanners/files/caching_file_reader.rb', line 13 def initialize super @cache = ::I18n::Tasks::Concurrent::Cache.new end |
Instance Method Details
#read_file(path) ⇒ String
Note:
This method is cached, it will only access the filesystem on the first invocation.
Return the contents of the file at the given path. The file is read in the ‘rb’ mode and UTF-8 encoding.
24 25 26 |
# File 'lib/i18n/tasks/scanners/files/caching_file_reader.rb', line 24 def read_file(path) @cache.fetch(File.(path)) { super } end |