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

New Feature - Read data from the RAM (don't always read the file content) #37

Open
samuelcarreira opened this issue Mar 27, 2018 · 9 comments

Comments

@samuelcarreira
Copy link

I dug up a little inside the conf module code and appears to me that each get/read function call uses the fs readFileSync to get the data from the config file.
If I need to constantly check for a value from the app settings it can lead to performance issues. So my approach is to copy the settings to a global variable 👎 and only use this module to write the config file when some changes occur.

Are any alternative approach to this problem or do you plan to add a feature to kinda "cache the values" and only reads the file when there are some changes?

Thank you

@cawa-93
Copy link

cawa-93 commented Nov 4, 2019

Totally agree. I was very surprised when I looked at the code and saw that all work with the file system is synchronous.

I think it would be much better to make a copy of the data in a global variable. And when you change this data, it is invisible, asynchronously, to synchronize it with a local file, if needed.

@sayem314
Copy link

Yeah, you are right, @sindresorhus any word?

@samuelcarreira
Copy link
Author

I am currently working on a alternative library to save the settings.
Main highlights:

  • Very lightweight (only native node modules)
  • Save/Read settings to/from RAM.
  • Uses fastest validation
  • Setting can be shared from the main process to the renderer process
  • only saves data to disk if needed (saves write cycles on SSDs)

I will post here when I publish the process

@sayem314
Copy link

@samuelcarreira waiting for this

@samuelcarreira
Copy link
Author

@sayem314 I am happy to announce that you can try the beta version of my module https://github.com/samuelcarreira/electron-json-settings-store
I need all the feedback that you can provide

@sayem314
Copy link

sayem314 commented Apr 6, 2020

@sayem314 I am happy to announce that you can try the beta version of my module https://github.com/samuelcarreira/electron-json-settings-store
I need all the feedback that you can provide

Is it for electron only? I don't use electron.

@papb
Copy link

papb commented Apr 7, 2020

Also Sindre Sorhus himself recommends his other module electron-store for electron

@samuelcarreira
Copy link
Author

@sayem314 It's only for electron

@papb the electron-store is basically a wrapper of the conf module, so the complaints are the same

@wkoncki
Copy link

wkoncki commented Oct 23, 2020

I just want to make everyone aware that this exists and does more or less what is required
https://github.com/SamVerschueren/cache-conf
It is however seriously outdated, so giving it a refresh may be a better course of work, rather than starting from scratch.

I am also wondering if this is an issue altogether, since modern operating systems usually have their own RAM cache for frequently used files. This is transparent for tools like node, but my guess is that file accessed multiple times a second will be cached, unless you are running very low on RAM.

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

5 participants