Class: Mustermann::PatternCache Private
- Inherits:
-
Object
- Object
- Mustermann::PatternCache
- Defined in:
- lib/mustermann/pattern_cache.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Mustermann::Pattern.new (which is used by new) will reuse instances that have not yet been garbage collected. You only need an extra cache if you do not keep a reference to the patterns around.
A simple, persistent cache for creating repositories.
Instance Method Summary collapse
-
#clear ⇒ Object
private
Removes all pattern instances from the cache.
- #create_pattern(string, **pattern_options) ⇒ Object private
-
#initialize(**pattern_options) ⇒ PatternCache
constructor
private
A new instance of PatternCache.
-
#size ⇒ Integer
private
Number of currently cached patterns.
Constructor Details
#initialize(**pattern_options) ⇒ PatternCache
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PatternCache.
24 25 26 27 28 |
# File 'lib/mustermann/pattern_cache.rb', line 24 def initialize(**) @cached = ::Set.new @mutex = Mutex.new @pattern_options = end |
Instance Method Details
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes all pattern instances from the cache.
41 42 43 |
# File 'lib/mustermann/pattern_cache.rb', line 41 def clear @mutex.synchronize { @cached.clear } end |
#create_pattern(string, **pattern_options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 |
# File 'lib/mustermann/pattern_cache.rb', line 34 def create_pattern(string, **) pattern = Mustermann.new(string, **, **@pattern_options) @mutex.synchronize { @cached.add(pattern) } unless @cached.include? pattern pattern end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns number of currently cached patterns.
46 47 48 |
# File 'lib/mustermann/pattern_cache.rb', line 46 def size @mutex.synchronize { @cached.size } end |