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

Persistence #204

Open
siennathesane opened this issue Feb 5, 2020 · 6 comments
Open

Persistence #204

siennathesane opened this issue Feb 5, 2020 · 6 comments

Comments

@siennathesane
Copy link
Collaborator

It would be great if bigcache had a feature where it could save it's state to disk so it could be restarted. I'm thinking there could be a storage interface which defined the API and then the initial implementation could be some base layout, like JSON or something.

type IStorage interface {
    Prepare() error // lock the entire cache.
    Save() (bool, error) // save the state to disk, return ok, error
    Load() (bool, error) // load from wherever, return ok, error
}

This has come up a few times and it might be an interesting interface to explore.

@neal-zhu
Copy link
Contributor

neal-zhu commented Mar 13, 2020

How about changing the interface to

type IStorage interface {
    Prepare() error // lock the entire cache.
    Save(io.Writer) (bool, error) // save the state to disk, return ok, error
    Load(io.Reader) (bool, error) // load from wherever, return ok, error
}

@cristaloleg
Copy link
Collaborator

@neal-zhu yep, this is definitely better. I'm thinking do we need to path context too?

@neal-zhu
Copy link
Contributor

neal-zhu commented Mar 13, 2020

Using io.Writer makes us free to save our data anywhere we like(maybe local disk, or a remote node or main memory). So I think path context is unnecessary?

@siennathesane
Copy link
Collaborator Author

I'm totally open to modifications on it, when I wrote this it was to open discussion, so I'm not married to the final decision so much as it was to surface this is an interface we'd want to implement.

I do agree that we don't need a path context and the Reader/Writer implementation is more than enough for the initial use cases. Partially because then it allows for disk, streaming, or some other method.

@neal-zhu
Copy link
Contributor

locking entire cache during persistence might not be acceptable, can we use a child process just like redis?

type IStorage interface {
    Save(string) chan error // fork a child process to dump entire cache
    Load(string) (bool, error) // load from wherever, return ok, error
}

@siennathesane
Copy link
Collaborator Author

I think having both a full-lock and a no-lock option would be good, but I think a full-lock could also be achieved upstream, so I'm open to a first pass and seeing what the community says. :)

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

No branches or pull requests

3 participants