i am trying to make a little express app which returns data from a postgres query.the query result should be cached in a Redis db. what I do is this:
app.get('/query_tile/:z/:x/:y', async (req: Request, res: Response) => { const client = new Client(connection); await client.connect(); const setHeader = () => { res.set('Content-Encoding', 'br'); res.set('Content-Type', 'application/x-protobuf'); res.set('Vary', 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers'); res.set('Content-Disposition', `attachment; filename=tile_${z}_${x}_${y}.mvt`); } const { z, x, y } = req.params; const cacheKey = `tile_${z}_${x}_${y}`; const cachedData = await redis.get(cacheKey); if (cachedData) { setHeader() res.send(brotliCompressSync(cachedData)); } else { const { rows } = await client.query('SELECT query_tile($1, $2, $3)', [z, x, y]); const data = rows[0]; const compressedData = brotliCompressSync(data.query_tile); await redis.set(cacheKey, data.query_tile); setHeader() res.send(compressedData); } client.end()});
the issue i am having is, that the cached result is not the same as the not cached one.what am i missing here?
both returns do have some data in it, but the one from the cache is not readable. at least not how i need it.
Thanks a lot for help!