diff options
author | Eric Wong <e@80x24.org> | 2022-01-24 08:43:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-01-24 11:26:28 +0000 |
commit | 6cc0ae1f3e365015fe219703ccab77b19db4705b (patch) | |
tree | e2e29b65f488a26ac5b895499f6ef7c46d1013ae /lib/dtas | |
parent | 9183c38754d76fcd778965350046738557d13722 (diff) | |
download | dtas-6cc0ae1f3e365015fe219703ccab77b19db4705b.tar.gz |
We still need the TTL to deal with fuse.sshfs and maybe other weird FSes which don't return the st_ctime properly.
Diffstat (limited to 'lib/dtas')
-rw-r--r-- | lib/dtas/mcache.rb | 13 |
1 files changed, 12 insertions, 1 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 @@ class DTAS::Mcache 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 |