arthurfiorette / axios-cache-interceptor

📬 Small and efficient cache interceptor for axios. Etag, Cache-Control, TTL, HTTP headers and more!
https://axios-cache-interceptor.js.org
MIT License
703 stars 58 forks source link

How to set maxAge? #862

Closed luiznasciment0 closed 4 months ago

luiznasciment0 commented 4 months ago

Hi! I was using axios-cache-adapter and now I want to migrate to axios-cache-interceptor.

Here is the code I have to handle axios-cache-adapter + axios:

const axios = require('axios')
const adapter = require('axios-cache-adapter')

const cache = adapter.setupCache({
  maxAge: 2 * 60 * 1000
})

const api = axios.create({
  adapter: cache.adapter
})

...

And here is the code I have in order to migrate to axios-cache-interceptor:

const axios = require('axios')
const { setupCache } = require('axios-cache-interceptor')

const axiosInstance = axios.create()

const api = setupCache(axiosInstance, {  /* here I would like to set maxAge just like I did with `axios-cache-adapter`  */  })

Can someone help me? Thanks

luiznasciment0 commented 4 months ago

I was wondering if the ttl option can be considered equivalent?

luiznasciment0 commented 4 months ago

Well, by reading the changelog and this commit I suppose ttl is the correct choice in this case. Thanks

arthurfiorette commented 4 months ago

yup, they are equivalent