From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH 3/3] player: expire sox metadata cache on file st_ctime changes
Date: Mon, 24 Jan 2022 11:35:50 +0000 [thread overview]
Message-ID: <20220124113550.19976-4-e@80x24.org> (raw)
In-Reply-To: <20220124113550.19976-1-e@80x24.org>
We still need the TTL to deal with fuse.sshfs and maybe other weird
FSes which don't return the st_ctime properly.
---
lib/dtas/mcache.rb | 13 ++++++++++++-
test/test_mcache.rb | 20 +++++++++++++++-----
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/lib/dtas/mcache.rb b/lib/dtas/mcache.rb
index 4f1e9e8..e0a39af 100644
--- a/lib/dtas/mcache.rb
+++ b/lib/dtas/mcache.rb
@@ -13,14 +13,25 @@ def initialize(shift = 8, ttl = 60)
def lookup(infile)
bucket = infile.hash & @mask
+ st = nil
if cur = @tbl[bucket]
if cur[:infile] == infile && (DTAS.now - cur[:btime]) < @ttl
- return cur
+ begin
+ st = File.stat(infile)
+ return cur if cur[:ctime] == st.ctime
+ rescue
+ end
end
end
return unless block_given?
@tbl[bucket] = begin
cur = cur ? cur.clear : {}
+ begin
+ st ||= File.stat(infile)
+ cur[:ctime] = st.ctime
+ rescue
+ return
+ end
if ret = yield(infile, cur)
ret[:infile] = infile.frozen? ? infile : -(infile.dup)
ret[:btime] = DTAS.now
diff --git a/test/test_mcache.rb b/test/test_mcache.rb
index 2bf0e98..983a69e 100644
--- a/test/test_mcache.rb
+++ b/test/test_mcache.rb
@@ -1,19 +1,29 @@
-# Copyright (C) 2016-2020 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require './test/helper'
require 'dtas/mcache'
+require 'tempfile'
class TestMcache < Testcase
def test_mcache
+ tmp = Tempfile.new(%W(tmp .sox))
+ fn = tmp.path
+ cmd = %W(sox -r 44100 -b 16 -c 2 -n #{fn} trim 0 1)
+ system(*cmd) or skip
mc = DTAS::Mcache.new
exist = nil
- mc.lookup('hello') { |infile, hash| exist = hash }
+ mc.lookup(fn) { |infile, hash|
+ hash[:ctime] = File.stat(infile).ctime
+ exist = hash
+ }
assert_kind_of Hash, exist
- assert_equal 'hello', exist[:infile]
+ assert_equal fn, exist[:infile]
assert_operator exist[:btime], :<=, DTAS.now
- assert_same exist, mc.lookup('hello')
+ assert_same exist, mc.lookup(fn)
assert_nil mc.lookup('HELLO')
- assert_same exist, mc.lookup('hello'), 'no change after miss'
+ assert_same exist, mc.lookup(fn), 'no change after miss'
+ ensure
+ tmp.close!
end
end
prev parent reply other threads:[~2022-01-24 11:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 11:35 [PATCH 0/3] some splitfx-related enhancements Eric Wong
2022-01-24 11:35 ` [PATCH 1/3] splitfx: support per-track environment variables Eric Wong
2022-01-24 11:35 ` [PATCH 2/3] splitfx: add --filter option to limit match to comments Eric Wong
2022-01-24 11:35 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://80x24.org/dtas/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220124113550.19976-4-e@80x24.org \
--to=e@80x24.org \
--cc=dtas-all@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
http://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).