Class: Ollama::Documents::MemoryCache
- Inherits:
-
Object
- Object
- Ollama::Documents::MemoryCache
- Includes:
- Enumerable
- Defined in:
- lib/ollama/documents/memory_cache.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
writeonly
Sets the attribute prefix.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(prefix:) ⇒ MemoryCache
constructor
A new instance of MemoryCache.
- #key?(key) ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(prefix:) ⇒ MemoryCache
Returns a new instance of MemoryCache.
2 3 4 5 |
# File 'lib/ollama/documents/memory_cache.rb', line 2 def initialize(prefix:) @prefix = prefix @data = {} end |
Instance Attribute Details
#prefix=(value) ⇒ Object (writeonly)
Sets the attribute prefix
7 8 9 |
# File 'lib/ollama/documents/memory_cache.rb', line 7 def prefix=(value) @prefix = value end |
Instance Method Details
#[](key) ⇒ Object
9 10 11 |
# File 'lib/ollama/documents/memory_cache.rb', line 9 def [](key) @data[pre(key)] end |
#[]=(key, value) ⇒ Object
13 14 15 |
# File 'lib/ollama/documents/memory_cache.rb', line 13 def []=(key, value) @data[pre(key)] = value end |
#clear ⇒ Object
29 30 31 32 |
# File 'lib/ollama/documents/memory_cache.rb', line 29 def clear @data.clear self end |
#delete(key) ⇒ Object
21 22 23 |
# File 'lib/ollama/documents/memory_cache.rb', line 21 def delete(key) @data.delete(pre(key)) end |
#each(&block) ⇒ Object
34 35 36 |
# File 'lib/ollama/documents/memory_cache.rb', line 34 def each(&block) @data.select { |key,| key.start_with?(@prefix) }.each(&block) end |
#key?(key) ⇒ Boolean
17 18 19 |
# File 'lib/ollama/documents/memory_cache.rb', line 17 def key?(key) @data.key?(pre(key)) end |
#size ⇒ Object
25 26 27 |
# File 'lib/ollama/documents/memory_cache.rb', line 25 def size @data.size end |