Module: Evanescence::Cacheable

Defined in:
lib/evanescence/cacheable.rb

Instance Method Summary collapse

Instance Method Details

#caches(options = {}) ⇒ Object



3
4
5
6
7
# File 'lib/evanescence/cacheable.rb', line 3

def caches(options = {})
  @by = options[:by]
  @max_size = options[:max_size]
  @cache = Evanescence.initialize_cache(max_size:)
end

#get_by(key) ⇒ Object



9
10
11
# File 'lib/evanescence/cacheable.rb', line 9

def get_by(key)
  cache.read(key) || send("find_by_#{by}", key)&.tap { |object| write_by(key, object) }
end

#write_by(key, value) ⇒ Object



13
14
15
# File 'lib/evanescence/cacheable.rb', line 13

def write_by(key, value)
  cache.write(key, value)
end