Class: Idempo::MemoryBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/idempo/memory_backend.rb

Defined Under Namespace

Classes: Store

Instance Method Summary collapse

Constructor Details

#initializeMemoryBackend

Returns a new instance of MemoryBackend.



2
3
4
5
6
7
# File 'lib/idempo/memory_backend.rb', line 2

def initialize
  require_relative "response_store"
  @lock = Idempo::MemoryLock.new
  @response_store = Idempo::ResponseStore.new
  @store_mutex = Mutex.new
end

Instance Method Details

#prune!Object



30
31
32
# File 'lib/idempo/memory_backend.rb', line 30

def prune!
  @response_store.prune
end

#with_idempotency_key(request_key) ⇒ Object



23
24
25
26
27
28
# File 'lib/idempo/memory_backend.rb', line 23

def with_idempotency_key(request_key)
  @lock.with(request_key) do
    store = Store.new(store_mutex: @store_mutex, response_store: @response_store, key: request_key)
    yield(store)
  end
end