Class: Juno::Lock

Inherits:
Proxy show all
Defined in:
lib/juno/lock.rb

Overview

Locks the underlying stores with a Mutex

Instance Attribute Summary

Attributes inherited from Proxy

#adapter

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #fetch

Constructor Details

#initialize(adapter, options = {}) ⇒ Lock

Constructor

Options:

  • :mutex - Mutex object (default Mutex.new)

Parameters:

  • adapter (Juno store)

    The underlying store

  • options (Hash) (defaults to: {})


14
15
16
17
# File 'lib/juno/lock.rb', line 14

def initialize(adapter, options = {})
  super
  @lock = options[:mutex] || Mutex.new
end

Instance Method Details

#clear(options = {}) ⇒ Object



35
36
37
38
# File 'lib/juno/lock.rb', line 35

def clear(options = {})
  @lock.synchronize { super }
  self
end

#closeObject



40
41
42
# File 'lib/juno/lock.rb', line 40

def close
  @lock.synchronize { super }
end

#delete(key, options = {}) ⇒ Object



31
32
33
# File 'lib/juno/lock.rb', line 31

def delete(key, options = {})
  @lock.synchronize { super }
end

#key?(key, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/juno/lock.rb', line 19

def key?(key, options = {})
  @lock.synchronize { super }
end

#load(key, options = {}) ⇒ Object



23
24
25
# File 'lib/juno/lock.rb', line 23

def load(key, options = {})
  @lock.synchronize { super }
end

#store(key, value, options = {}) ⇒ Object



27
28
29
# File 'lib/juno/lock.rb', line 27

def store(key, value, options = {})
  @lock.synchronize { super }
end