Auto-update the cache (for cached models) when inserting/deleting

This commit is contained in:
Colin McDonald 2016-06-24 23:54:34 -04:00
parent ef3f7345e5
commit a255d45603
4 changed files with 16 additions and 0 deletions

View File

@ -82,6 +82,8 @@ public final class BannedAsn {
}
public void insert(SingleResultCallback<Void> callback) {
bannedAsnCache.add(this);
bannedAsnIdCache.put(id, this);
bannedAsnsCollection.insertOne(this, callback);
}
@ -90,6 +92,8 @@ public final class BannedAsn {
}
public void delete(SingleResultCallback<DeleteResult> callback) {
bannedAsnCache.remove(this);
bannedAsnIdCache.remove(id);
bannedAsnsCollection.deleteOne(new Document("_id", id), callback);
}

View File

@ -78,10 +78,14 @@ public final class Rank {
}
public void insert(SingleResultCallback<Void> callback) {
rankCache.add(this);
rankIdCache.put(id, this);
ranksCollection.insertOne(this, callback);
}
public void delete(SingleResultCallback<DeleteResult> callback) {
rankCache.remove(this);
rankIdCache.remove(id);
ranksCollection.deleteOne(new Document("_id", id), callback);
}

View File

@ -89,6 +89,8 @@ public final class Server {
}
public void insert(SingleResultCallback<Void> callback) {
serverCache.add(this);
serverIdCache.put(id, this);
serversCollection.insertOne(this, callback);
}
@ -97,6 +99,8 @@ public final class Server {
}
public void delete(SingleResultCallback<DeleteResult> callback) {
serverCache.remove(this);
serverIdCache.remove(id);
serversCollection.deleteOne(new Document("_id", id), callback);
}

View File

@ -77,6 +77,8 @@ public final class ServerGroup {
}
public void insert(SingleResultCallback<Void> callback) {
serverGroupCache.add(this);
serverGroupIdCache.put(id, this);
serverGroupsCollection.insertOne(this, callback);
}
@ -85,6 +87,8 @@ public final class ServerGroup {
}
public void delete(SingleResultCallback<DeleteResult> callback) {
serverGroupCache.remove(this);
serverGroupIdCache.remove(id);
serverGroupsCollection.deleteOne(new Document("_id", id), callback);
}