Skip to content

Commit

Permalink
[fix](metaCache)fix bug that names cache can not invalidate.
Browse files Browse the repository at this point in the history
  • Loading branch information
hubgeter committed Jan 2, 2025
1 parent 04d7927 commit 6110a3c
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

public class MetaCache<T> {
private LoadingCache<String, List<Pair<String, String>>> namesCache;
//Pair<String, String> : <Remote name, Local name>
private Map<Long, String> idToName = Maps.newConcurrentMap();
private LoadingCache<String, Optional<T>> metaObjCache;

Expand Down Expand Up @@ -114,12 +115,25 @@ public void updateCache(String objName, T obj, long id) {
idToName.put(id, objName);
}

public void updateCache(String remoteName, String localName, T obj, long id) {
metaObjCache.put(localName, Optional.of(obj));
namesCache.asMap().compute("", (k, v) -> {
if (v == null) {
return Lists.newArrayList(Pair.of(remoteName, localName));
} else {
v.add(Pair.of(remoteName, localName));
return v;
}
});
idToName.put(id, localName);
}

public void invalidate(String objName, long id) {
namesCache.asMap().compute("", (k, v) -> {
if (v == null) {
return Lists.newArrayList();
} else {
v.remove(objName);
v.removeIf(pair -> pair.value().equals(objName));
return v;
}
});
Expand Down

0 comments on commit 6110a3c

Please sign in to comment.