Class: Ollama::Documents::MemoryCache

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ollama/documents/memory_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute prefix to.



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

#clearObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/ollama/documents/memory_cache.rb', line 17

def key?(key)
  @data.key?(pre(key))
end

#sizeObject



25
26
27
# File 'lib/ollama/documents/memory_cache.rb', line 25

def size
  @data.size
end