Class: Estated::RequestCache
- Inherits:
-
Object
- Object
- Estated::RequestCache
- Defined in:
- lib/estated/request_cache.rb
Class Method Summary collapse
Class Method Details
.read(path, params) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/estated/request_cache.rb', line 6 def read(path, params) document = cache_store. find(cache_key: cache_key(path, params)). limit(1). first document['payload'] if document end |
.setup ⇒ Object
30 31 32 33 34 35 |
# File 'lib/estated/request_cache.rb', line 30 def setup cache_store.indexes.create_one({ cache_key: 1 }, unique: true) cache_store.indexes.create_one( { created_at: 1 }, expire_after_seconds: Estated.config.cache_ttl) end |
.write(path, params, payload) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/estated/request_cache.rb', line 15 def write(path, params, payload) cache_store.update_one( { cache_key: cache_key(path, params) }, { cache_key: cache_key(path, params), payload: payload, created_at: Time.now }, upsert: true ) true end |