Class: Tilt::Cache
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt.rb
Overview
Tilt::Cache is a thin wrapper around Hash. It has the following limitations:
-
Not thread-safe.
-
Size is unbounded.
-
Keys are not copied defensively, and should not be modified after being passed to #fetch. More specifically, the values returned by key#hash and key#eql? should not change.
If this is too limiting for you, use a different cache implementation.
Extremely simple template cache implementation. Calling applications create a Tilt::Cache instance and use #fetch with any set of hashable arguments (such as those to Tilt.new):
cache = Tilt::Cache.new
cache.fetch(path, line, ) { Tilt.new(path, line, ) }
Subsequent invocations return the already loaded template object.
Instance Method Summary collapse
-
#clear ⇒ Object
Clears the cache.
-
#fetch(*key) { ... } ⇒ Object
Caches a value for key, or returns the previously cached value.
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
92 93 94 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt.rb', line 92 def initialize @cache = {} end |
Instance Method Details
#clear ⇒ Object
Clears the cache.
109 110 111 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt.rb', line 109 def clear @cache = {} end |
#fetch(*key) { ... } ⇒ Object
Caches a value for key, or returns the previously cached value. If a value has been previously cached for key then it is returned. Otherwise, block is yielded to and its return value which may be nil, is cached under key and returned.
102 103 104 105 106 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt.rb', line 102 def fetch(*key) @cache.fetch(key) do @cache[key] = yield end end |