Class: Ollama::Documents::MemoryCache
  
  
  
  
  
    - Inherits:
- 
      Object
      
        
          - Object
- Ollama::Documents::MemoryCache
 show all
      - Includes:
- Enumerable, Cache::Common
    - Defined in:
- lib/ollama/documents/cache/memory_cache.rb
 
  Instance Attribute Summary
  
  
  #prefix
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  
  #collections, #pre, #unpre
  Constructor Details
  
    
  
  
    #initialize(prefix:)  ⇒ MemoryCache 
  
  
  
  
    
Returns a new instance of MemoryCache.
   
 
  
  
    | 
6
7
8
9 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 6
def initialize(prefix:)
  @prefix = prefix
  @data   = {}
end | 
 
  
 
  
    Instance Method Details
    
      
  
  
    #[](key)  ⇒ Object 
  
  
  
  
    | 
11
12
13 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 11
def [](key)
  @data[pre(key)]
end | 
 
    
      
  
  
    #[]=(key, value)  ⇒ Object 
  
  
  
  
    | 
15
16
17 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 15
def []=(key, value)
  @data[pre(key)] = value
end | 
 
    
      
  
  
    #clear  ⇒ Object 
  
  
  
  
    | 
31
32
33
34 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 31
def clear
  @data.delete_if { |key, _| key.start_with?(@prefix) }
  self
end | 
 
    
      
  
  
    #delete(key)  ⇒ Object 
  
  
  
  
    | 
23
24
25 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 23
def delete(key)
  @data.delete(pre(key))
end | 
 
    
      
  
  
    #each(&block)  ⇒ Object 
  
  
  
  
    | 
36
37
38 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 36
def each(&block)
  @data.select { |key,| key.start_with?(@prefix) }.each(&block)
end | 
 
    
      
  
  
    #full_each(&block)  ⇒ Object 
  
  
  
  
    | 
41
42
43 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 41
def full_each(&block)
  @data.each(&block)
end | 
 
    
      
  
  
    #key?(key)  ⇒ Boolean 
  
  
  
  
    | 
19
20
21 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 19
def key?(key)
  @data.key?(pre(key))
end | 
 
    
      
  
  
    #size  ⇒ Object 
  
  
  
  
    | 
27
28
29 | # File 'lib/ollama/documents/cache/memory_cache.rb', line 27
def size
  count
end |