Class: Cache::Client
- Inherits:
-
Object
- Object
- Cache::Client
- Defined in:
- lib/cache-client.rb,
lib/cache-client.rb,
lib/cache-client/error.rb,
lib/cache-client/utils.rb,
lib/cache-client/version.rb,
lib/cache-client/key_builder.rb
Defined Under Namespace
Classes: Error, KeyBuilder, Utils
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
Instance Method Summary collapse
- #fetch(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(backend, *args) ⇒ Client
constructor
A new instance of Client.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(backend, *args) ⇒ Client
Returns a new instance of Client.
15 16 17 18 |
# File 'lib/cache-client.rb', line 15 def initialize(backend, *args) backend = Cache::Backend::NoopBackend if !args.empty? && args.compact.empty? @backend = backendify(backend).new(*args) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
14 15 16 |
# File 'lib/cache-client.rb', line 14 def backend @backend end |
Instance Method Details
#fetch(key) ⇒ Object
28 29 30 31 32 |
# File 'lib/cache-client.rb', line 28 def fetch(key) existing_value = get(key) return existing_value if existing_value set(key, yield) end |
#get(key) ⇒ Object
24 25 26 |
# File 'lib/cache-client.rb', line 24 def get(key) @backend.get(keyify(key)) end |
#set(key, value) ⇒ Object
20 21 22 |
# File 'lib/cache-client.rb', line 20 def set(key, value) @backend.set(keyify(key), value) end |