Module: Waylon::Cache
- Defined in:
- lib/waylon/cache.rb
Overview
Used for working with the Moneta store for caching
Constant Summary collapse
- DefaultStorage =
Moneta.new( :Redis, url: "redis://#{ENV.fetch("REDIS", "localhost:6379")}/1" )
Class Method Summary collapse
- .adapter ⇒ Object
- .clear ⇒ Object
- .delete(key) ⇒ Object
- .key?(name) ⇒ Boolean
- .load(key, expires: nil) ⇒ Object
- .storage ⇒ Object
- .storage=(storage) ⇒ Object
- .store(key, value, expires: nil) ⇒ Object
Class Method Details
.adapter ⇒ Object
11 12 13 |
# File 'lib/waylon/cache.rb', line 11 def self.adapter storage.adapter end |
.clear ⇒ Object
15 16 17 |
# File 'lib/waylon/cache.rb', line 15 def self.clear storage.clear end |
.delete(key) ⇒ Object
19 20 21 |
# File 'lib/waylon/cache.rb', line 19 def self.delete(key) storage.delete(key) end |
.key?(name) ⇒ Boolean
23 24 25 |
# File 'lib/waylon/cache.rb', line 23 def self.key?(name) storage.key?(name) end |
.load(key, expires: nil) ⇒ Object
27 28 29 |
# File 'lib/waylon/cache.rb', line 27 def self.load(key, expires: nil) expires ? storage.load(key, expires:) : storage.load(key) end |
.storage ⇒ Object
39 40 41 |
# File 'lib/waylon/cache.rb', line 39 def self.storage @storage ||= DefaultStorage end |
.storage=(storage) ⇒ Object
43 44 45 |
# File 'lib/waylon/cache.rb', line 43 def self.storage=(storage) @storage = storage end |
.store(key, value, expires: nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/waylon/cache.rb', line 31 def self.store(key, value, expires: nil) if expires storage.store(key, value, expires:) else storage.store(key, value) end end |