Add support for caching parallel requests #201
Replies: 10 comments 1 reply
-
Hey @emilbonnek |
Beta Was this translation helpful? Give feedback.
-
They are talking about several different svgs in multiple sessions, I am talking about a single svg in one session. I don't think it is the same thing that is being discussed. I already saw their issue before I made this. |
Beta Was this translation helpful? Give feedback.
-
The cache is only populated after one of the requests succeed. |
Beta Was this translation helpful? Give feedback.
-
Yes, it doesn't store it in the cache until it has a successful response. So when users use the same svg multiple times on page the svg ressource will be fetched several times. This is the bug I specified above. I realize it can be solved in user-land, but wouldn't you consider this a worthwhile feature request for this library as well? Since it is already doing caching, I think it should also be able to avoid ressources being requested in parallel. |
Beta Was this translation helpful? Give feedback.
-
Hey @emilbonnek I'll convert this issue to discussions and gather user feedback. |
Beta Was this translation helpful? Give feedback.
-
I will continue to refer to this as a bug - despite not being part of the design. I expected the caching to work similarly to how the browser caches resources fetched declaratively with an |
Beta Was this translation helpful? Give feedback.
-
It's quite relevant in my case to have this parallel caching too - could you point me in the right direction on how to achieve it if that's not on a library roadmap? @emilbonnek @gilbarbara |
Beta Was this translation helpful? Give feedback.
-
Maybe there's something to be done in the Rework this part (https://github.com/gilbarbara/react-inlinesvg/blob/v3.0.2/src/index.tsx#L269): if (cache && cache.status === STATUS.LOADED) {
this.handleLoad(cache.content, true);
return;
} By something like this if (cache && [STATUS.PENDING, STATUS.LOADING, STATUS.LOADED].includes(cache.status)) {
if (cache.status === STATUS.LOADED) {
this.handleLoad(cache.content, true);
return;
}
setTimeout(() => this.load(), 100);
return;
} I know that |
Beta Was this translation helpful? Give feedback.
-
Hey @emilbonnek @SzymonGalazka @dtrucs I finally got some time to work on caching. I needed to move the caching to another module so every component instance shares it and can be manipulated and create a polling flow so the cache waits to resolve if there's already a request for the same file. You can check the implementation here While doing that, I started playing with the Cache API, which works great.
So it isn't worth implementing it right now. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Multiple instances cache and browser permanent cache added in v4.x |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
The caching doesn't seem to work when several requests get kicked off at once in a next js project.
To Reproduce
cacheRequests={true}
andonLoad={(src, hasCache) => console.log(src, hasCache)}
Navigation to second page
Navigation to the first page
Expected behavior
Navigation to second page
Navigation to the first page
Beta Was this translation helpful? Give feedback.
All reactions