offline support

master
Bel LaPointe 2021-02-28 01:33:25 -06:00
parent 13fc57eacb
commit 6670a6de6c
1 changed files with 17 additions and 9 deletions

View File

@ -1398,7 +1398,7 @@
try
{
this.deltas.popEach((key) => {
console.log("syncing to replicas: " + key);
console.log("syncing: " + key);
this.replicate(key);
});
}
@ -1429,14 +1429,20 @@
replicate(key)
{
var value = this.cache().get(key);
this.replicateOne(this.primary(), key, value);
this.replicas().forEach((database) => {
if (value)
database.set(key, value);
else
database.del(key, value);
this.replicateOne(database, key, value);
});
}
replicateOne(database, key, value)
{
if (value)
database.set(key, value);
else
database.del(key);
}
get(key)
{
return this.cache().get(key);
@ -1444,11 +1450,12 @@
set(key, value)
{
this.primary().set(key, value);
this.deltas.push(key);
try
{
this.replicas().forEach((database) => {
this.cache().set(key, value);
this.primary().set(key, value);
this.replicas().slice(1).forEach((database) => {
database.set(key, value);
});
this.deltas.pop(key);
@ -1461,11 +1468,12 @@
del(key)
{
this.primary().del(key);
this.deltas.push(key);
try
{
this.replicas().forEach((database) => {
this.cache().del(key);
this.primary().del(key);
this.replicas().slice(1).forEach((database) => {
database.del(key);
});
this.deltas.pop(key);