Module: Apicraft::Concerns::Cacheable
- Included in:
- Openapi::Contract
- Defined in:
- lib/apicraft/concerns/cacheable.rb
Overview
Simple cache structure to not fetch the same data multiple times from the contracts
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.cache ⇒ Object
16 17 18 |
# File 'lib/apicraft/concerns/cacheable.rb', line 16 def self.cache @cache end |
Instance Method Details
#with_cache(key) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/apicraft/concerns/cacheable.rb', line 20 def with_cache(key) data = Cacheable.cache[key] return data[:content] if data.present? c = yield Cacheable.cache[key] = { content: c } if c.present? c end |