Mutiny Multi and Quarkus Caching

443 views
Skip to first unread message

Manuel Wallrapp

unread,
Feb 9, 2022, 4:09:21 AM2/9/22
to Quarkus Development mailing list
Hi everyone

We used mutiny to develop our backend services. We cached some data with the Quarkus  @CacheResult annotation. While this works ok for Uni's, since Caffein also uses Uni's under the hood. 
How is caching done for Multi's? 
It would be great to have a more clear explanation how to cache Uni's AND Multi's in the Quarkus caching guide.

If in the @CacheResult annotated method I subscribe to a multi and collect it and then return a Uni<List<MyType>> it tells me, I am blocking the thread.  

@CacheResult(cacheName = BITBUCKET_REPO_BRANCHES)
public Uni<List<GitBranchDto>> getBranchesForRepo(String projectKey, String repositorySlug) {
return Uni.createFrom().item(
bitbucketClient.getBranchesForRepo(projectKey, repositorySlug, PageRequest.fetchAll())
.subscribe()
.asStream()
.collect(Collectors.toList()))
;
}

In general I miss also a guide for caching in the Mutiny Guide. 

Thanks for your help

Manu

clement escoffier

unread,
Feb 13, 2022, 3:37:01 AM2/13/22
to Quarkus Development mailing list
Hello,

I don't believe we support caching Multi. Julien Ponge is working on a Multi operator that may let you do this (replay, which will replay the last items). 

In your code, you are blocking because `asStream` returns a blocking stream. So, it blocks until you read all the items (and accumulate them in a list). It would have been similar to:

```
List<GitBranchDto> list = .... # get the list using a blocking API
return Uni.createFrom().item(list);
```

You need to do something like:

```

@CacheResult(cacheName = BITBUCKET_REPO_BRANCHES)
public Uni<List<GitBranchDto>> getBranchesForRepo(String projectKey, String repositorySlug) {
 return bitbucketClient.getBranchesForRepo(projectKey, repositorySlug, PageRequest.fetchAll()).collect().asList();
}
```

The difference is that you do not block. You return a Uni that will emit its item when you read all the items from the Multi.

Clement

Julien Ponge

unread,
Feb 14, 2022, 3:40:19 AM2/14/22
to Clement Escoffier, Quarkus Development mailing list
Replaying of Multi is indeed on the radar (and it's a not that simple!).
--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages