mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-13 17:46:36 +00:00
Fix cache filepath
This commit is contained in:
parent
d2e7f44800
commit
e72e4f3f8d
15
src/Cache.js
15
src/Cache.js
@ -3,15 +3,16 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const defaultFilename = 'orbit-db-cache.json';
|
const defaultFilepath = path.resolve('./orbit-db-cache.json');
|
||||||
|
let filePath = defaultFilepath;
|
||||||
let cache = {};
|
let cache = {};
|
||||||
|
|
||||||
class Cache {
|
class Cache {
|
||||||
static set(key, value) {
|
static set(key, value) {
|
||||||
cache[key] = value;
|
cache[key] = value;
|
||||||
fs.writeFile(path.resolve(defaultFilename), JSON.stringify(cache, null, 2) + "\n", (err) => {
|
fs.writeFile(filePath, JSON.stringify(cache, null, 2) + "\n", (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
// console.log('It\'s saved!', path.resolve(defaultFilename));
|
// console.log('It\'s saved!', filePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,10 +21,10 @@ class Cache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static loadCache(cacheFile) {
|
static loadCache(cacheFile) {
|
||||||
cacheFile = cacheFile ? cacheFile : defaultFilename;
|
filePath = cacheFile ? cacheFile : defaultFilepath;
|
||||||
if(fs.existsSync(path.resolve(defaultFilename))) {
|
if(fs.existsSync(filePath)) {
|
||||||
console.log('Load cache from', path.resolve(defaultFilename));
|
console.log('Load cache from', filePath);
|
||||||
cache = JSON.parse(fs.readFileSync(path.resolve(defaultFilename)));
|
cache = JSON.parse(fs.readFileSync(filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user