node-localstorage icon indicating copy to clipboard operation
node-localstorage copied to clipboard

Support optional persistence.

Open knpwrs opened this issue 9 years ago • 10 comments

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.

knpwrs avatar Nov 18 '15 17:11 knpwrs

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.

lmaccherone avatar Nov 18 '15 17:11 lmaccherone

Perhaps a generic storage provider interface.

knpwrs avatar Nov 18 '15 17:11 knpwrs

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.

lmaccherone avatar Nov 18 '15 17:11 lmaccherone

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

NickColley avatar Dec 07 '15 11:12 NickColley

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

knpwrs avatar Dec 07 '15 14:12 knpwrs

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.

LuminescentMoon avatar Jul 06 '16 09:07 LuminescentMoon

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 avatar Jul 06 '16 12:07 lmaccherone

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

lmaccherone avatar Aug 08 '18 18:08 lmaccherone

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

lmaccherone avatar Nov 25 '21 13:11 lmaccherone

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

trasherdk avatar Dec 08 '21 08:12 trasherdk

Closing due to lack of interest

lmaccherone avatar Jul 25 '23 17:07 lmaccherone