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.
- #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.
158 159 160 161 162 |
# File 'lib/iknow_cache.rb', line 158 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.
156 157 158 |
# File 'lib/iknow_cache.rb', line 156 def cache_group @cache_group end |
#cache_options ⇒ Object (readonly)
Returns the value of attribute cache_options.
156 157 158 |
# File 'lib/iknow_cache.rb', line 156 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
156 157 158 |
# File 'lib/iknow_cache.rb', line 156 def name @name end |
Instance Method Details
#delete(key, parent_path: nil, **options) ⇒ Object
189 190 191 192 193 |
# File 'lib/iknow_cache.rb', line 189 def delete(key, parent_path: nil, **) p = path(key, parent_path) Rails.logger.debug("Cache Delete: #{p}") if DEBUG Rails.cache.delete(p, IknowCache.(, )) end |
#fetch(key, parent_path: nil, **options, &block) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/iknow_cache.rb', line 164 def fetch(key, parent_path: nil, **, &block) p = path(key, parent_path) Rails.logger.debug("Cache Fetch: #{p}") if DEBUG v = Rails.cache.fetch(p, IknowCache.(, ), &block) Rails.logger.debug("=> #{v.inspect}") if DEBUG v end |
#read(key, parent_path: nil, **options) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/iknow_cache.rb', line 172 def read(key, parent_path: nil, **) p = path(key, parent_path) Rails.logger.debug("Cache Read: #{p}") if DEBUG v = Rails.cache.read(p, IknowCache.(, )) Rails.logger.debug("=> #{v.inspect}") if DEBUG v end |
#read_multi(keys) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/iknow_cache.rb', line 195 def read_multi(keys) return {} if keys.blank? key_paths = path_multi(keys) path_keys = key_paths.invert Rails.logger.debug("Cache Multi-Read: #{key_paths.values.inspect}") if DEBUG raw = Rails.cache.read_multi(*key_paths.values) vs = raw.each_with_object({}) do |(path, value), h| h[path_keys[path]] = value end Rails.logger.debug("=> #{vs.inspect}") if DEBUG vs end |
#write(key, value, parent_path: nil, **options) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/iknow_cache.rb', line 180 def write(key, value, parent_path: nil, **) p = path(key, parent_path) if DEBUG Rails.logger.debug("Cache Store: #{p} (#{IknowCache.merge_options(cache_options, options).inspect})") Rails.logger.debug("<= #{value.inspect}") end Rails.cache.write(p, value, IknowCache.(, )) end |
#write_multi(entries, options = nil) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/iknow_cache.rb', line 210 def write_multi(entries, = nil) return {} if entries.blank? key_paths = path_multi(entries.keys) = IknowCache.(, ) entries.each do |key, value| Rails.logger.debug("Cache Multi-Write: #{key_paths[key]}") if DEBUG Rails.cache.write(key_paths[key], value, ) end end |