Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Cache #11

Closed
plopez01 opened this issue Apr 30, 2018 · 6 comments
Closed

Set Cache #11

plopez01 opened this issue Apr 30, 2018 · 6 comments

Comments

@plopez01
Copy link

plopez01 commented Apr 30, 2018

Please, it would be great to be possible to re-load the cache, or set it to something, becouse i edit the json file and the cache doesn't get updated.

@jonschlinkert
Copy link
Owner

jonschlinkert commented May 1, 2018

Make sure you have the latest version of data-store, and use the API (call .load()) to get the store instead of node's fs methdods. Otherwise you might be trying to load the store before a write has been performed.

Also note that there have been some changes to internals in 2.0. It sounds like you were using private properties, there is no longer a .cache property in 2.0.

edit: @doowb changed to 2.0 (this is published to npm but currently still in the dev branch)

@plopez01
Copy link
Author

plopez01 commented May 5, 2018

Thanks, im going to update data-store and see if works. Im using gists to download a json and set that download json to the .json file of data-store, my problem was that when i update the json, the "data" doesn't get updated until i restart my app. Let's see if updating helps.

@plopez01
Copy link
Author

plopez01 commented May 6, 2018

I am calling store.load() and it's not working. Let me show my code.

gists.download({id: 'ID of gist'}, function(err, res) {
  let finalconte = JSON.parse(conte);
  baseDatos = finalconte.files['abc.json'].content
  store.load(baseDatos);
});

This code is not loading the content of the gist to the store, and I don't know why.

@doowb
Copy link
Collaborator

doowb commented May 6, 2018

@plopez01 store.load() re-loads the json file into memory. It doesn't take any arguments.
If you do the following, then it will re-load the store, then update it with the new values:

store.load();
store.set(baseDatos);

If you want to completely overwrite the file with the new data, then you can do this:

// this will overwrite the entire object, then save it to the file.
store.data = baseDatos;

@jonschlinkert
Copy link
Owner

jonschlinkert commented May 11, 2018

you don't need to call .load() for loading data, you should just do store.set(object) or store.set(key, val). That will automatically update the persisted data and in-memory data. If that still doesn't work let us know.

edit: doh! I just realized that I hadn't published version 3.0! I was obviously confused, and I'm sure I confused you guys as well. Apologies!

@plopez01 try again with 3.0 and let me know if you have any issues. thanks!

@plopez01
Copy link
Author

Well thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants