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

feat: Support for IntoIterator #841

Open
BjarneSeger opened this issue Jan 17, 2025 · 4 comments
Open

feat: Support for IntoIterator #841

BjarneSeger opened this issue Jan 17, 2025 · 4 comments
Labels
feature New feature or request
Milestone

Comments

@BjarneSeger
Copy link

I use foyer in an application I have yet to release as a cache for a few things but I don't always have the exact key to a value, or need all values from the cache. This currently did not seem (easily) doable.
Might it be possible (and make sense) to add Rusts IntoIterator trait to HybridCache?

@MrCroxx
Copy link
Collaborator

MrCroxx commented Jan 17, 2025

Hi @BjarneSeger , thank you for reporting.

I agree with you. Introducing IntoIterator will make things easier. However, as a thread-safe cache without transaction guarantees, it is hard to get the snapshot of the full content at a moment. Does it work for you? If not, may I ask for more details about your scenario?

@MrCroxx MrCroxx added the feature New feature or request label Jan 17, 2025
@MrCroxx MrCroxx added this to the Planning milestone Jan 17, 2025
@BjarneSeger
Copy link
Author

Thanks for responding so quickly!
Because I previously tried working with a few non thread-safe crates and channels, this was something I completely missed.
The easiest solution I could come up with is just storing the known keys in a Vec, iterating over it and then get all the results from the cache, but in that scenario I still need to store and recover the known keys on restart.

I'd only iterate over HybridCache when starting for building a GUI. Future updates to it are managed through a db Struct and sent to that GUI, so this did not seem like that much of an issue in my case. However, my case is not everyone's case.

The Caches ordering is not consistent, so this may be difficult, but might it be possible to get a slice into it that is lazily checked? This does not account for additions to the HybridCache, but it would be a start and more efficient than cloning?

@MrCroxx
Copy link
Collaborator

MrCroxx commented Jan 17, 2025

IMHO, I think the ideal solution is to iterator over the underlying db, and use foyer as a read-through cache.

I understand that would be hard because the interfaces are hard to combine. Let me see what I can do. Would you like to share about what db and crates you are using for in your project? It will help a lot.

@BjarneSeger
Copy link
Author

Sorry, I think I was not clear:

  • The GUI received initial information on how to populate the view and can request additional info through the db struct.
  • db is just a struct made up of a TcpStream, a PathBuf for the cachedir, and three HybridCaches for persistent data.

The db is just an abstraction over the cache, if something cannot be found in the local cache, it queries the server for it. But the GUI does not need to now, it just calls a function get_user().
So foyer is the local database that is queried.
I hope this clarified things. Let me know if you have any more questions!

@MrCroxx MrCroxx pinned this issue Jan 18, 2025
@MrCroxx MrCroxx unpinned this issue Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants