Memoize for a duration based on the memoized item #909
-
I am caching http response and would like to invalidate based on the content of the response but the BooleanSupplier is not fed with the item. More precisely, i'm fetching a JWT token and an access token response is providing a "expires_in" value. I'm trying to make the memoize honor this value. Ideally, something like Uni.createFrom().item(new AccessTokenResponse())
.memoize().atLeast(item -> item.getExpiresIn()) or Uni.createFrom().item(new AccessTokenResponse())
.memoize().until(item -> item.getExpiresIn() + item.getGeneratedAt() < System.nanoTime()) Is it something possible ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Fun fact: Exactly your case let to the memoize operator, that's there today ;) There were implementation but also design reasons that made it quite challenging to invalidate based on checks on the cached item. My solution (up to now) was to have an validation on the jwt before consuming it, thowing some kind of expiry exception that cases a retry of the whole pipeline (that starts with requesting a fresh jwt). But some time has passed by, I'm really curious, if there might be a solution in your sense possible. |
Beta Was this translation helpful? Give feedback.
Fun fact: Exactly your case let to the memoize operator, that's there today ;)
For the full story have a look to this issue and the linked PRs: #231
There were implementation but also design reasons that made it quite challenging to invalidate based on checks on the cached item.
My solution (up to now) was to have an validation on the jwt before consuming it, thowing some kind of expiry exception that cases a retry of the whole pipeline (that starts with requesting a fresh jwt).
But some time has passed by, I'm really curious, if there might be a solution in your sense possible.