Skip to content

Why use future over sync? #284

Answered by tatsuya6502
waynerobinson asked this question in Q&A
Discussion options

You must be logged in to vote

Hi. Sorry for late reply.

Although async version of Moka cache will be slightly slower than sync cache, we would recommend to use async cache when it is used within async context (i.e. from Tokio). Async cache will never block the executor threads of async runtime, while sync cache may (i.e. when waiting for a lock). Async cache will keep the async runtime responsive.

Here are some obvious examples:

  1. get_with method (doc):
    • This method takes a user function to initialize the value for the key.
    • If the key does not exist, get_with will evaluate the user function to get the value to insert.
    • Concurrent calls on the same not-existing key are coalesced into one evaluation of the user function.
      • T…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@waynerobinson
Comment options

Answer selected by tatsuya6502
Comment options

You must be logged in to vote
4 replies
@tatsuya6502
Comment options

@tatsuya6502
Comment options

@tatsuya6502
Comment options

@tatsuya6502
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants