Class: Cachew::Adapter
- Inherits:
-
Object
- Object
- Cachew::Adapter
- Defined in:
- lib/cachew/adapter.rb
Overview
Base class for Cachew adapters.
Constant Summary collapse
- UNDEFINED =
Internal constant used by ‘__get__` to notify that value is not in the cache or became stale
Object.new.freeze
Instance Method Summary collapse
Instance Method Details
#fetch(key, opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cachew/adapter.rb', line 46 def fetch(key, opts = {}) key = __key__ key, opts val = __get__ key if UNDEFINED.equal? val val = yield ttl = opts.fetch(:ttl) { 0 }.to_i __set__ key, val, ttl end val end |