Module: YiffSpace::Utils::Cache
- Defined in:
- lib/yiffspace/utils/cache.rb
Class Method Summary collapse
- .clear ⇒ Object
- .delete(key) ⇒ Object
- .fetch(key, expires_in: nil) ⇒ Object
- .read_multi(keys, prefix) ⇒ Object
- .redis ⇒ Object
- .write(key, value, expires_in: nil) ⇒ Object
Class Method Details
.clear ⇒ Object
29 30 31 |
# File 'lib/yiffspace/utils/cache.rb', line 29 def clear Rails.cache.clear end |
.delete(key) ⇒ Object
25 26 27 |
# File 'lib/yiffspace/utils/cache.rb', line 25 def delete(key) Rails.cache.delete(key) end |
.fetch(key, expires_in: nil) ⇒ Object
17 18 19 |
# File 'lib/yiffspace/utils/cache.rb', line 17 def fetch(key, expires_in: nil, &) Rails.cache.fetch(key, expires_in: expires_in, &) end |
.read_multi(keys, prefix) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/yiffspace/utils/cache.rb', line 8 def read_multi(keys, prefix) sanitized_key_to_key_hash = keys.index_by { |key| "#{prefix}:#{key}" } sanitized_keys = sanitized_key_to_key_hash.keys sanitized_key_to_value_hash = Rails.cache.read_multi(*sanitized_keys) sanitized_key_to_value_hash.transform_keys(&sanitized_key_to_key_hash) end |
.redis ⇒ Object
33 34 35 36 37 |
# File 'lib/yiffspace/utils/cache.rb', line 33 def redis # Using a shared variable like this here is OK # since pitchfork spawns a new process for each worker @redis ||= Redis.new(url: YiffSpace.config.redis_url.call) end |
.write(key, value, expires_in: nil) ⇒ Object
21 22 23 |
# File 'lib/yiffspace/utils/cache.rb', line 21 def write(key, value, expires_in: nil) Rails.cache.write(key, value, expires_in: expires_in) end |