lmaccherone / node-localstorage

A drop-in substitute for the browser native localStorage API that runs on node.js.
MIT License
450 stars 36 forks source link

Support optional persistence. #15

Closed knpwrs closed 1 year ago

knpwrs commented 9 years ago

I think having the option of not persisting data would be helpful. I just need this for running unit-tests where data shouldn't persist past the current run.

lmaccherone commented 9 years ago

There is a method for deleting the folder created _deleteLocation().

However, an in-memory only storage option might be nice. I'll look at how hard that might be to add.

knpwrs commented 9 years ago

Perhaps a generic storage provider interface.

lmaccherone commented 9 years ago

I took a look and it will be more than just a little work to implement an in-memory option. I propose that if no directory is provided when it's instantiated, that it default to in-memory storage. I don't have time to do it just now, but maybe in the next week or so. Of course, if you do it yourself before then, I'll gladly accept a well coded and tested pull request.

A generic storage provider interface is a lot more work than even just adding an in-memory option. Again, I'd welcome a well coded and tested pull request for this if you're up for it.

NickColley commented 8 years ago

https://github.com/gr2m/localstorage-memory might work for your usecase?

knpwrs commented 8 years ago

@nickcolley That looks nice but optional persistence would still be awesome.

LuminescentMoon commented 8 years ago

It only requires a miniscule amount of work if mock-fs is used. You literally just require mock-fs in place of NodeJS's fs module and ensure the sole dependency of this project follows suit.

lmaccherone commented 8 years ago

That is a good option. I'm using npm package write-file-atomic for writes but that's only in one spot in the code and I could easily just check a conditional and use mock-fs for that whenever it's in-memory mode. I'll put it on the list to try in the next week... unless you want to submit a pull request. ;-)

lmaccherone commented 6 years ago

@LuminescentMoon 's idea is a really simple way to accomplish this. Anyone want to implement it and submit a pull request?

lmaccherone commented 2 years ago

I would still love to do this if someone needs it.

trasherdk commented 2 years ago

Well, #76 would need something. I was thinking MySQL / Redis maybe combined with BroadcastChannel

lmaccherone commented 1 year ago

Closing due to lack of interest