Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Edge Caching PAAPI Transactions on Vercel

I'm making a call to Amazon's paapi on a Nextjs site hosted on Vercel. Like most API's, Amazon limits the number of transactions per second and per day. I'm using the amazon-paapi React library inside of an API route at pages/api/amazon-product.js.

I'm using Cache-Control to achieve this:

export default async function handler(req, res) {
    const { productId } = req.body

    const {commonParameters, requestParameters} = getRequestParams(productId)

    amazonPaapi.GetItems(commonParameters, requestParameters)
    .then(response => {
        // Cache response to reduce API calls
        res.setHeader('Cache-Control', 's-maxage=86400')
        return res.status(201).json({ data: response.ItemsResult.Items[0] })
    })
    .catch(error => {
        return res.status(400).json({
            error: error
        })
    });
}

Since res.setHeader() is inside of the amazonPaapi.GetItems() method, I'm wondering if it wouldn't cache because that method will be called regardless of whether what it returns is cached?

It seems like we'd want to check whether max age has expired before we call the amazonPaapi.GetItems() method. Is this the case? If so, how can we do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your implementation assumes that the clients for your API respects the cache header and it works fine in that case. However it doesn't protect from clients which explicitly decides to ignore the cache header.

In such cases, you will want to create a cache in your code with the key that uniquely identifies the Amazon API call. You can set the expiry on this cache and only call Amazon API after a specified duration.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda