Class: IknowCache::Cache
- Inherits:
-
Object
- Object
- IknowCache::Cache
- Defined in:
- lib/iknow_cache.rb
Constant Summary collapse
- DEBUG =
false
Instance Attribute Summary collapse
-
#cache_group ⇒ Object
readonly
Returns the value of attribute cache_group.
-
#cache_options ⇒ Object
readonly
Returns the value of attribute cache_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #delete(key, parent_path: nil, **options) ⇒ Object
- #fetch(key, parent_path: nil, **options, &block) ⇒ Object
-
#initialize(cache_group, name, cache_options) ⇒ Cache
constructor
A new instance of Cache.
- #key ⇒ Object
- #read(key, parent_path: nil, **options) ⇒ Object
- #read_multi(keys) ⇒ Object
- #write(key, value, parent_path: nil, **options) ⇒ Object
- #write_multi(entries, options = nil) ⇒ Object
Constructor Details
#initialize(cache_group, name, cache_options) ⇒ Cache
Returns a new instance of Cache.
198 199 200 201 202 |
# File 'lib/iknow_cache.rb', line 198 def initialize(cache_group, name, ) @cache_group = cache_group @name = name = IknowCache.(cache_group., ).try { |x| x.dup.freeze } end |
Instance Attribute Details
#cache_group ⇒ Object (readonly)
Returns the value of attribute cache_group.
196 197 198 |
# File 'lib/iknow_cache.rb', line 196 def cache_group @cache_group end |
#cache_options ⇒ Object (readonly)
Returns the value of attribute cache_options.
196 197 198 |
# File 'lib/iknow_cache.rb', line 196 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
196 197 198 |
# File 'lib/iknow_cache.rb', line 196 def name @name end |
Instance Method Details
#delete(key, parent_path: nil, **options) ⇒ Object
229 230 231 232 233 |
# File 'lib/iknow_cache.rb', line 229 def delete(key, parent_path: nil, **) p = path(key, parent_path) IknowCache.logger.debug("Cache Delete: #{p}") if DEBUG IknowCache.cache.delete(p, IknowCache.(, )) end |
#fetch(key, parent_path: nil, **options, &block) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/iknow_cache.rb', line 204 def fetch(key, parent_path: nil, **, &block) p = path(key, parent_path) IknowCache.logger.debug("Cache Fetch: #{p}") if DEBUG v = IknowCache.cache.fetch(p, IknowCache.(, ), &block) IknowCache.logger.debug("=> #{v.inspect}") if DEBUG v end |
#key ⇒ Object
262 263 264 |
# File 'lib/iknow_cache.rb', line 262 def key cache_group.key end |
#read(key, parent_path: nil, **options) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/iknow_cache.rb', line 212 def read(key, parent_path: nil, **) p = path(key, parent_path) IknowCache.logger.debug("Cache Read: #{p}") if DEBUG v = IknowCache.cache.read(p, IknowCache.(, )) IknowCache.logger.debug("=> #{v.inspect}") if DEBUG v end |
#read_multi(keys) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/iknow_cache.rb', line 235 def read_multi(keys) return {} if keys.blank? key_paths = path_multi(keys) path_keys = key_paths.invert IknowCache.logger.debug("Cache Multi-Read: #{key_paths.values.inspect}") if DEBUG raw = IknowCache.cache.read_multi(*key_paths.values) vs = raw.each_with_object({}) do |(path, value), h| h[path_keys[path]] = value end IknowCache.logger.debug("=> #{vs.inspect}") if DEBUG vs end |
#write(key, value, parent_path: nil, **options) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/iknow_cache.rb', line 220 def write(key, value, parent_path: nil, **) p = path(key, parent_path) if DEBUG IknowCache.logger.debug("Cache Store: #{p} (#{IknowCache.merge_options(cache_options, options).inspect})") IknowCache.logger.debug("<= #{value.inspect}") end IknowCache.cache.write(p, value, IknowCache.(, )) end |
#write_multi(entries, options = nil) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/iknow_cache.rb', line 250 def write_multi(entries, = nil) return {} if entries.blank? key_paths = path_multi(entries.keys) = IknowCache.(, ) entries.each do |key, value| IknowCache.logger.debug("Cache Multi-Write: #{key_paths[key]}") if DEBUG IknowCache.cache.write(key_paths[key], value, ) end end |