Class: Ollama::Documents::RedisBackedMemoryCache
- Inherits:
-
MemoryCache
- Object
- MemoryCache
- Ollama::Documents::RedisBackedMemoryCache
show all
- Defined in:
- lib/ollama/documents/cache/redis_backed_memory_cache.rb
Instance Attribute Summary collapse
#prefix
Instance Method Summary
collapse
Methods inherited from MemoryCache
#[], #each, #full_each, #key?, #size
#collections, #pre, #unpre
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
|
# 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'
@prefix, @url, @object_class = prefix, url, object_class
@redis_cache = Ollama::Documents::RedisCache.new(prefix:, url:, object_class:)
@redis_cache.full_each do |key, value|
@data[key] = value
end
end
|
Instance Attribute Details
#object_class ⇒ Object
Returns the value of attribute object_class.
15
16
17
|
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 15
def object_class
@object_class
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
21
22
23
24
|
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 21
def []=(key, value)
super
redis.set(pre(key), JSON(value))
end
|
#clear ⇒ Object
32
33
34
35
36
|
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 32
def clear
redis.scan_each(match: "#@prefix*") { |key| redis.del(key) }
super
self
end
|
#delete(key) ⇒ Object
26
27
28
29
30
|
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 26
def delete(key)
result = redis.del(pre(key))
super
result
end
|
#redis ⇒ Object
17
18
19
|
# File 'lib/ollama/documents/cache/redis_backed_memory_cache.rb', line 17
def redis
@redis_cache.redis
end
|