diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java index 0798e83de..a273b659e 100644 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java +++ b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java @@ -42,7 +42,7 @@ public class FilePerKeyMap implements Map, Closeable { private final Thread fileFpmWatcher; private volatile boolean closed = false; private boolean putReturnsNull; - private boolean snappyValues; + private ThrowingFunction reading = i -> i; private ThrowingFunction writing = o -> o; @@ -112,9 +112,10 @@ public class FilePerKeyMap implements Map, Closeable { public String put(String key, String value) { if (closed) throw new IllegalStateException("closed"); Path path = dirPath.resolve(key); + FileRecord fr = lastFile.get(path.toFile()); String existingValue = putReturnsNull ? null : getFileContents(path); writeToFile(path, value); - + if (fr != null) fr.valid = false; return existingValue; } @@ -174,7 +175,7 @@ public class FilePerKeyMap implements Map, Closeable { try { File file = path.toFile(); FileRecord last = lastFile.get(file); - if (last != null && file.lastModified() == last.timestamp) + if (last != null && last.valid && file.lastModified() == last.timestamp) return last.contents; return getFileContents0(path); } catch (IOException ioe) { @@ -219,10 +220,6 @@ public class FilePerKeyMap implements Map, Closeable { this.putReturnsNull = putReturnsNull; } - public void snappyValues(boolean snappyValues) { - this.snappyValues = snappyValues; - } - private static class FPMEntry implements Entry { private String key; private String value; @@ -350,6 +347,7 @@ public class FilePerKeyMap implements Map, Closeable { class FileRecord { final long timestamp; + boolean valid = true; final String contents; FileRecord(long timestamp, String contents) {