allOrigins icon indicating copy to clipboard operation
allOrigins copied to clipboard

Caching

Open ShaCP opened this issue 6 years ago • 9 comments

Can a response ever be cached? I'm noticing it always downloads the resource I request even if it hasn't changed.

ShaCP avatar Apr 22 '20 08:04 ShaCP

I would like to work on this enhancement. Can I start working on this?

07souravkunda avatar Jun 25 '20 03:06 07souravkunda

Hi. Thanks for working on this. I'm noticing that I'm still getting a 200 response instead of 304. It's still downloading the resource. I don't see an etag in the response headers from cloudflare. Is this working as intended?

ShaCP avatar Jul 27 '20 00:07 ShaCP

Some websites don't manage etag response header.

07souravkunda avatar Jul 27 '20 06:07 07souravkunda

For me everything is cached. I need to fetch new data on every 15s. Is there a way to bypass cache?

ttimot24 avatar Mar 02 '21 23:03 ttimot24

I put in a hack which greatly improves performance. It returns a 304 if the user has a cached version and doesn't check to see if there is a new version. Change processRequest to return a 304 if the request come with an etag.

async function processRequest(req, res) {
  const startTime = new Date()
  const params = parseParams(req)

  if (params.requestMethod === 'OPTIONS') {
    return res.end()
  }
  let page = { 'status':304, } 

    if( typeof req.headers['if-none-match'] !=='undefined' ) { 

return res.status(304).send()
}
 else {

page = await getPage(params)
}

	 
  return createResponse(page, params, res, startTime)
}

unparagoned avatar Mar 31 '21 22:03 unparagoned

Is there a way to prevent the server from returning a cached response? I'm getting a resource in a previous state when I know it has changed since the last time I fetched it.

jherrera avatar Apr 09 '22 02:04 jherrera

same. would like to bypass cache please

TripleG58 avatar May 04 '22 00:05 TripleG58

Would also like to force uncached requests. Maybe allow uncached when this header is send:

{headers: {'Cache-Control': 'no-cache'}}

MetaIdea avatar Jun 03 '22 00:06 MetaIdea

I was able to get uncached results by appending a random number as a get parameter. See below. fetch('https://api.allorigins.win/get?url=' + encodeURIComponent(url) + '&rand=' + Math.random())

TripleG58 avatar Jun 04 '22 05:06 TripleG58