Class: Idempo::ActiveRecordBackend::Store
- Inherits:
-
Struct
- Object
- Struct
- Idempo::ActiveRecordBackend::Store
- Defined in:
- lib/idempo/active_record_backend.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key
12 13 14 |
# File 'lib/idempo/active_record_backend.rb', line 12 def key @key end |
#model ⇒ Object
Returns the value of attribute model
12 13 14 |
# File 'lib/idempo/active_record_backend.rb', line 12 def model @model end |
Instance Method Details
#lookup ⇒ Object
13 14 15 |
# File 'lib/idempo/active_record_backend.rb', line 13 def lookup model.where(idempotent_request_key: key).where("expire_at > ?", Time.now).first&.idempotent_response_payload end |
#store(data:, ttl:) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/idempo/active_record_backend.rb', line 17 def store(data:, ttl:) # MySQL does not support datetime with subsecont precision, so ceil() it is expire_at = Time.now.utc + ttl.ceil model.transaction do model.where(idempotent_request_key: key).delete_all model.create(idempotent_request_key: key, idempotent_response_payload: data, expire_at: expire_at) end true end |