add caching #561
Replies: 6 comments
-
I've managed to do this using the apicache npm module |
Beta Was this translation helpful? Give feedback.
-
@trickydisco78 can you share your solution? |
Beta Was this translation helpful? Give feedback.
-
Yep: here: https://glitch.com/~flint-garage But i've now found this which is much better : https://github.com/daniloc/airtable-api-proxy |
Beta Was this translation helpful? Give feedback.
-
I'm aware this is closed, but If anybody finds this in 2019 via Google as I did, I came up with a solution I think works well. I'm using express and http-proxy-middleware. Essentially the cache middleware just runs before the proxy middleware. The only tricky part is getting the response from the proxy. Here's my solution:
This is simply using the proxyMiddleware as per the examples, but running a cache middleware first. The cache middleware (only for GET requests) checks if the path is in cache, and if so returns the body from cache and ends the route handler. If it's not in cache it passes on to the proxy handler, but first modifies the res.end (there are other ways to do this, but this seems to be the most reliable?) function to grab a copy of the response body and store in cache. |
Beta Was this translation helpful? Give feedback.
-
@sebtoombs I like your solution but seem to be getting an It seems to be something about the Buffer but my research is saying the Buffer concat is the answer but you already have that in place... |
Beta Was this translation helpful? Give feedback.
-
this function is working for me now
|
Beta Was this translation helpful? Give feedback.
-
Anyone managed to add caching to the onProxyReq option?
I've added a memory caching function to onProxyReq
proxy middleware configuration
It looks like it's not grabbing the body information or getting to set the cache at
body comes up as null as wel
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions