Class: Stagecraft::Renderer::PipelineCache
- Inherits:
-
Object
- Object
- Stagecraft::Renderer::PipelineCache
- Defined in:
- lib/stagecraft/renderer/pipeline_cache.rb
Defined Under Namespace
Classes: Key
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(limit: 256, on_change: nil) ⇒ PipelineCache
constructor
A new instance of PipelineCache.
- #size ⇒ Object
Constructor Details
#initialize(limit: 256, on_change: nil) ⇒ PipelineCache
Returns a new instance of PipelineCache.
13 14 15 16 17 18 19 |
# File 'lib/stagecraft/renderer/pipeline_cache.rb', line 13 def initialize(limit: 256, on_change: nil) @limit = Integer(limit) raise ArgumentError, "pipeline cache limit must be positive" unless @limit.positive? @entries = {} @on_change = on_change end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
11 12 13 |
# File 'lib/stagecraft/renderer/pipeline_cache.rb', line 11 def limit @limit end |
Instance Method Details
#clear ⇒ Object
39 40 41 42 43 44 |
# File 'lib/stagecraft/renderer/pipeline_cache.rb', line 39 def clear @entries.each_value { |value| release(value) } @on_change&.call(-@entries.length) @entries.clear self end |
#fetch(key) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stagecraft/renderer/pipeline_cache.rb', line 21 def fetch(key) if @entries.key?(key) value = @entries.delete(key) @entries[key] = value return value end value = yield @entries[key] = value @on_change&.call(1) evict! while @entries.length > limit value end |
#size ⇒ Object
35 36 37 |
# File 'lib/stagecraft/renderer/pipeline_cache.rb', line 35 def size @entries.size end |