Sha256: a5b09ef889eaa5d89b05906ab949a7609222bd9ae9ccbeac157d742a3f59bd97
Contents?: true
Size: 893 Bytes
Versions: 12
Compression:
Stored size: 893 Bytes
Contents
# frozen_string_literal: true require 'i18n/tasks/scanners/files/file_reader' module I18n::Tasks::Scanners::Files # Reads the files in 'rb' mode and UTF-8 encoding. # Wraps a {FileReader} and caches the results. # # @note This class is thread-safe. All methods are cached. # @since 0.9.0 class CachingFileReader < FileReader def initialize super @mutex = Mutex.new @cache = {} end # Return the contents of the file at the given path. # The file is read in the 'rb' mode and UTF-8 encoding. # # @param (see FileReader#read_file) # @return (see FileReader#read_file) # @note This method is cached, it will only access the filesystem on the first invocation. def read_file(path) absolute_path = File.expand_path(path) @cache[absolute_path] || @mutex.synchronize { @cache[absolute_path] ||= super } end end end
Version data entries
12 entries across 12 versions & 1 rubygems