class ActiveSupport::Cache::FileStore

def lock_file(file_name, &block)

Lock a file for a block so only one process can modify it at a time.
def lock_file(file_name, &block)
  if File.exist?(file_name)
    File.open(file_name, "r+") do |f|
      f.flock File::LOCK_EX
      yield
    ensure
      f.flock File::LOCK_UN
    end
  else
    yield
  end
end