mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Invalidate the cache record on an update.
This commit is contained in:
@@ -42,7 +42,7 @@ public class FilePerKeyMap implements Map<String, String>, Closeable {
|
||||
private final Thread fileFpmWatcher;
|
||||
private volatile boolean closed = false;
|
||||
private boolean putReturnsNull;
|
||||
private boolean snappyValues;
|
||||
|
||||
private ThrowingFunction<InputStream, InputStream, IOException> reading = i -> i;
|
||||
private ThrowingFunction<OutputStream, OutputStream, IOException> writing = o -> o;
|
||||
|
||||
@@ -112,9 +112,10 @@ public class FilePerKeyMap implements Map<String, String>, 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<String, String>, 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<String, String>, Closeable {
|
||||
this.putReturnsNull = putReturnsNull;
|
||||
}
|
||||
|
||||
public void snappyValues(boolean snappyValues) {
|
||||
this.snappyValues = snappyValues;
|
||||
}
|
||||
|
||||
private static class FPMEntry<String> implements Entry<String, String> {
|
||||
private String key;
|
||||
private String value;
|
||||
@@ -350,6 +347,7 @@ public class FilePerKeyMap implements Map<String, String>, Closeable {
|
||||
|
||||
class FileRecord {
|
||||
final long timestamp;
|
||||
boolean valid = true;
|
||||
final String contents;
|
||||
|
||||
FileRecord(long timestamp, String contents) {
|
||||
|
||||
Reference in New Issue
Block a user