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

Can Moka combine entries ? #353

Closed
lynn2910 opened this issue Nov 24, 2023 · 3 comments · Fixed by #370
Closed

Can Moka combine entries ? #353

lynn2910 opened this issue Nov 24, 2023 · 3 comments · Fixed by #370
Labels
question Further information is requested

Comments

@lynn2910
Copy link

Hello,
I've just discovered this crate and I'm thinking of using it, but I haven't found any information about combining inputs.

To put it simply, for my project, I have data that is not complete, and depending on what I receive from the API, I can update the cache with fields that have changed or are non-existent.
Is this possible with Moka?

@peter-scholtens
Copy link
Contributor

The original author of the crate is hospitalized, see #352.

I think you can solve that problem by making an Arc<Mutex<T>> of your data T and store a clone of that in the cache while holding the original reference. As an example, see how I try to access the same data by Cache and by Btree in example #350

@tatsuya6502 tatsuya6502 added the question Further information is requested label Dec 23, 2023
@tatsuya6502
Copy link
Member

Sorry for a late reply.

Right, you can solve the problem by making an Arc<Mutex<T>> or Arc<RwLock<T>> of your data T. However there are some limitations on expiration, eviction listener and size-based eviction. This is because you are modifying cached value without calling any cache API so cache's internal data structures like the LRU queue and expiration timers cannot be updated. For more details of the limitations, see the lower part of this issue comment.

To remove such limitations, I am currently working on the following new feature:

You might want to use the and_upsert_with method, although you will still need to use Arc<Mutex<T>> or Arc<RwLock<T>>. For more details, see this example append_value_async.rs in the pull request.

@tatsuya6502
Copy link
Member

I am reviewing #370 now and will merge it today. I will publish moka v0.12.3 hopefully in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants