about summary refs log tree commit homepage
path: root/lib/dtas/mcache.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/mcache.rb')
-rw-r--r--lib/dtas/mcache.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/dtas/mcache.rb b/lib/dtas/mcache.rb
index b638a23..e0a39af 100644
--- a/lib/dtas/mcache.rb
+++ b/lib/dtas/mcache.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 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
 # encoding: binary
@@ -13,16 +13,27 @@ 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.freeze
+        ret[:infile] = infile.frozen? ? infile : -(infile.dup)
         ret[:btime] = DTAS.now
       end
       ret