Class: RubyLlmMesh::Cache::MemoryStore
- Inherits:
-
Object
- Object
- RubyLlmMesh::Cache::MemoryStore
- Defined in:
- lib/ruby_llm_mesh/cache/memory_store.rb
Overview
Process-local vector entry store used when Redis is unavailable.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #all ⇒ Object
- #clear! ⇒ Object
-
#initialize ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #size ⇒ Object
- #write(id:, prompt:, embedding:, payload:, ttl:) ⇒ Object
Constructor Details
#initialize ⇒ MemoryStore
Returns a new instance of MemoryStore.
9 10 11 12 |
# File 'lib/ruby_llm_mesh/cache/memory_store.rb', line 9 def initialize @entries = [] @mutex = Mutex.new end |
Instance Method Details
#all ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ruby_llm_mesh/cache/memory_store.rb', line 14 def all @mutex.synchronize do now = Time.now @entries.reject! { |e| e.expires_at && e.expires_at <= now } @entries.map(&:dup) end end |
#clear! ⇒ Object
38 39 40 |
# File 'lib/ruby_llm_mesh/cache/memory_store.rb', line 38 def clear! @mutex.synchronize { @entries.clear } end |
#size ⇒ Object
42 43 44 |
# File 'lib/ruby_llm_mesh/cache/memory_store.rb', line 42 def size all.length end |
#write(id:, prompt:, embedding:, payload:, ttl:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_llm_mesh/cache/memory_store.rb', line 22 def write(id:, prompt:, embedding:, payload:, ttl:) expires_at = ttl && ttl.positive? ? Time.now + ttl : nil entry = Entry.new( id: id, prompt: prompt, embedding: , payload: payload, expires_at: expires_at ) @mutex.synchronize do @entries.reject! { |e| e.id == id } @entries << entry end true end |