Class: SprocketsDerailleur::FileStore

Inherits:
Sprockets::Cache::FileStore
  • Object
show all
Defined in:
lib/sprockets-derailleur/file_store.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Lookup value in cache



16
17
18
# File 'lib/sprockets-derailleur/file_store.rb', line 16

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

#[]=(key, value) ⇒ Object

Save value to cache



21
22
23
# File 'lib/sprockets-derailleur/file_store.rb', line 21

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

#lockObject



8
9
10
11
12
13
# File 'lib/sprockets-derailleur/file_store.rb', line 8

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

#with_lock(type) ⇒ Object



25
26
27
28
29
30
# File 'lib/sprockets-derailleur/file_store.rb', line 25

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