Class: Ollama::Documents::RedisBackedMemoryCache
- Inherits:
-
MemoryCache
- Object
- MemoryCache
- Ollama::Documents::RedisBackedMemoryCache
- Defined in:
- lib/ollama/documents/cache/redis_backed_memory_cache.rb
Instance Attribute Summary collapse
-
#object_class ⇒ Object
readonly
Returns the value of attribute object_class.
Attributes included from Cache::Common
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(prefix:, url: ENV['REDIS_URL'], object_class: nil) ⇒ RedisBackedMemoryCache
constructor
A new instance of RedisBackedMemoryCache.
- #redis ⇒ Object
Methods inherited from MemoryCache
#[], #each, #full_each, #key?, #size
Methods included from Cache::Common
Methods included from Utils::Math
#convert_to_vector, #cosine_similarity, #norm
Constructor Details
#initialize(prefix:, url: ENV['REDIS_URL'], object_class: nil) ⇒ RedisBackedMemoryCache
Returns a new instance of RedisBackedMemoryCache.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 5 def initialize(prefix:, url: ENV['REDIS_URL'], object_class: nil) super(prefix:) url or raise ArgumentError, 'require redis url' @url, @object_class = url, object_class @redis_cache = Ollama::Documents::RedisCache.new(prefix:, url:, object_class:) @redis_cache.extend(Ollama::Documents::Cache::Records::RedisFullEach) @redis_cache.full_each do |key, value| @data[key] = value end end |
Instance Attribute Details
#object_class ⇒ Object (readonly)
Returns the value of attribute object_class.
16 17 18 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 16 def object_class @object_class end |
Instance Method Details
#[]=(key, value) ⇒ Object
22 23 24 25 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 22 def []=(key, value) super redis.set(pre(key), JSON(value)) end |
#clear ⇒ Object
33 34 35 36 37 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 33 def clear redis.scan_each(match: "#@prefix*") { |key| redis.del(key) } super self end |
#delete(key) ⇒ Object
27 28 29 30 31 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 27 def delete(key) result = redis.del(pre(key)) super result end |
#redis ⇒ Object
18 19 20 |
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 18 def redis @redis_cache.redis end |