Class: LockMethod::DefaultStorageClient

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/lock_method/default_storage_client.rb

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#delete(k) ⇒ Object



23
24
25
# File 'lib/lock_method/default_storage_client.rb', line 23

def delete(k)
  ::FileUtils.rm_f path(k)
end

#flushObject



27
28
29
# File 'lib/lock_method/default_storage_client.rb', line 27

def flush
  ::FileUtils.rm_rf dir
end

#get(k) ⇒ Object



8
9
10
11
12
# File 'lib/lock_method/default_storage_client.rb', line 8

def get(k)
  return unless ::File.exist? path(k)
  ::Marshal.load ::File.read(path(k))
rescue ::Errno::ENOENT
end

#set(k, v, ttl) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/lock_method/default_storage_client.rb', line 14

def set(k, v, ttl)
  semaphore.synchronize do
    ::File.open(path(k), ::File::RDWR|::File::CREAT) do |f|
      f.flock ::File::LOCK_EX
      f.write ::Marshal.dump(v)
    end
  end
end