Module: SprocketsDerailleur::FileStoreExtension

Included in:
FileStore
Defined in:
lib/sprockets-derailleur/file_store_extension.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Lookup value in cache



14
15
16
# File 'lib/sprockets-derailleur/file_store_extension.rb', line 14

def [](key)
  with_lock(File::LOCK_SH) { super }
end

#[]=(key, value) ⇒ Object

Save value to cache



19
20
21
# File 'lib/sprockets-derailleur/file_store_extension.rb', line 19

def []=(key, value)
  with_lock(File::LOCK_EX) { super }
end

#lockObject



6
7
8
9
10
11
# File 'lib/sprockets-derailleur/file_store_extension.rb', line 6

def lock
  @lock ||= begin
    FileUtils.mkdir_p @root
    File.open(@root.join("lock"), File::RDWR|File::CREAT)
  end
end

#with_lock(type) ⇒ Object



23
24
25
26
27
28
# File 'lib/sprockets-derailleur/file_store_extension.rb', line 23

def with_lock(type)
  Timeout::timeout(SprocketsDerailleur.configuration.file_lock_timeout) { lock.flock(type) }
  yield
ensure
  lock.flock(File::LOCK_UN)
end