Class: Nauvisian::Cache::FileSystem
- Inherits:
-
Object
- Object
- Nauvisian::Cache::FileSystem
- Defined in:
- lib/nauvisian/cache/file_system.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(key) ⇒ Object
-
#initialize(name:, ttl: MINIMUM_TTL) ⇒ FileSystem
constructor
A new instance of FileSystem.
Constructor Details
#initialize(name:, ttl: MINIMUM_TTL) ⇒ FileSystem
Returns a new instance of FileSystem.
16 17 18 19 20 21 |
# File 'lib/nauvisian/cache/file_system.rb', line 16 def initialize(name:, ttl: MINIMUM_TTL) raise ArgumentError, "ttl is too small (must be >= #{MINIMUM_TTL})" if ttl < MINIMUM_TTL @cache_directory = self.class.cache_root / name @ttl = ttl end |
Class Method Details
Instance Method Details
#fetch(key) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/nauvisian/cache/file_system.rb', line 25 def fetch(key) path = generate_path(key) return path.binread if path.exist? && !stale?(path, Time.now) yield.tap {|content| store(path, content) } end |