Comments (1)
You can use the .load
method to "re-load" the data from the file.
If the code your writing could potentially have multiple instances of data-store
accessing the same file at the same time, then you should probably "wrap" .get
and .set
to call .load
before those operations to ensure the data in memory is current.
const store = require('data-store')({ path: process.cwd() + '/foo.json' });
const get = (...args) => {
store.load();
return store.get(...args);
};
const set = (...args) => {
store.load();
return store.set(...args);
};
Or you can extend the Store
class:
const { Store } = require('data-store');
class MyStore extends Store {
get(...args) {
this.load();
return super.get(...args);
}
set(...args) {
this.load();
return super.set(...args);
}
del(...args) {
this.load();
return super.del(...args);
}
hasOwn(...args) {
this.load();
return super.hasOwn(...args);
}
clone(...args) {
this.load();
return super.clone(...args);
}
}
Even doing that, there is still a possibility of race conditions since multiple instances are accessing the same file.
from data-store.
Related Issues (20)
- TypeError: Class constructor Store cannot be invoked without 'new' HOT 2
- store.set() key with dot dymbol HOT 1
- Inconsistency of undefined HOT 1
- Delete object inside array HOT 1
- error while using del method in typescript HOT 1
- Does store.load() delete the data?
- store.clear into store.set into store.load deletes whole store HOT 2
- Create optional lock file for use of the data-store by external process HOT 7
- Release Notes ? HOT 1
- Retrieving data-store HOT 1
- deprecated isObject HOT 1
- decreated isObject HOT 1
- NPM owner HOT 3
- v4.1.0 has not been published to npm HOT 6
- Does not seem to save new data, but reverts back to old data. HOT 6
- Data-store wont save anything. HOT 2
- How to pass a variable as key
- Depends on 2 high severity vulnerabilities
- Data store not reading correctly the file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data-store.