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) ⇒ Mustermann::Pattern
private
Pattern corresponding to string.
-
#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.
23 24 25 26 27 |
# File 'lib/mustermann/pattern_cache.rb', line 23 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.
40 41 42 |
# File 'lib/mustermann/pattern_cache.rb', line 40 def clear @mutex.synchronize { @cached.clear } end |
#create_pattern(string, **pattern_options) ⇒ Mustermann::Pattern
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 pattern corresponding to string.
33 34 35 36 37 |
# File 'lib/mustermann/pattern_cache.rb', line 33 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.
45 46 47 |
# File 'lib/mustermann/pattern_cache.rb', line 45 def size @mutex.synchronize { @cached.size } end |