jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.57k stars 95 forks source link

Initial Draft to fix the case where the DiskCache doesn't persist #192

Closed BaxHugh closed 7 months ago

BaxHugh commented 7 months ago

Initial attempt at providing a resolution to https://github.com/jaemk/cached/issues/190.

I haven't looked at all options, this is just the first solution I saw. I think there's probably some config / setting for sled that should do this for us?

omid commented 7 months ago

As far as I see... sled automatically fsyncs every 500ms by default, which looks fine to me.

jaemk commented 7 months ago

Thanks @BaxHugh - could you add a flag to the cache type to optionally enable this? Not every use-case requires a hard fsync on every operation. An option would need to be added to the IO macro also

BaxHugh commented 7 months ago

Great thanks for the feedback @jaemk and @omid, I'll update with an option to the macro. So the io_cached macro is generic for any io based cache right?. This sync to disk on cache_set option currently would only be implemented for the specific DiskCache. I think the simplest thing to implement would be to add the boolean flag in the io_cache macro args, stating that only some backends (DiskCache) currently support it, so it may not do anything for other backends.

BaxHugh commented 7 months ago

The changes here are now based upon https://github.com/jaemk/cached/pull/193, I can't stage PRs on that one, as the branch is in my clone. But the PR in my clone: https://github.com/BaxHugh/cached/pull/1 shows just the changes relating to this feature