Hi <@UFGCACPE0>! Just wondering if Pedestal Cache ...
# opensavvy
d
Hi @CLOVIS! Just wondering if Pedestal Cache is capable of making a "queue" to run image format generation when an original image url is provided, return the generated format if available, if not, return the url in all "generated formats" as a fallback, and start the generation for the next requests to that url...
c
Hey! What's the queue used for, here?
Everything else you can do, yes. I'm just not sure what the queue is
d
Say I have an original image saved in s3, I need to generate different sizes and store them in the s3 bucket those urls to the new files should be returned, and as a fallback (if they haven't been generated yet), the original url should be returned as all the formats.
But if I generate too many at a time I get OOMs
So I need to limit the parallelism
I wanted to use a Semaphore, but I still need to return images that were already generated and not send requests to generate images that were already done
c
So, the cache is always an intermediate pull-layer. What that means is, flow of control always looks like:
Copy code
caller → cache → some service
Since you always control both the caller and the implementation service, what you can do is use a Semaphore in the service. The cache will only call the service if it doesn't know the result already, so the semaphore will only be used for actual requests and won't slow down results-from-cache.
Also, since the cache returns a flow of progress events, you can detect that the cache is making a very first request (it's a Loading event) and using
Flow.map
to replace it by whichever default value you want
d
That's sound nice, thanks @CLOVIS! Now I'm just wondering how complicated it would be to implement a Redis caching layer, since I'm running on k8s with multiple instances...
c
Fairly simple actually! You can see the
Cache
interface? You can implement it and do whatever
Just be careful of reading all its documentation, there are a few tricky things in the contract, but it should be fine
Also, if you do do this, I wouldn't mind a PR 😇
👍🏼 1