Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching #55

Open
ShaCP opened this issue Apr 22, 2020 · 9 comments
Open

Caching #55

ShaCP opened this issue Apr 22, 2020 · 9 comments

Comments

@ShaCP
Copy link

ShaCP commented Apr 22, 2020

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

@07souravkunda
Copy link

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

@ShaCP
Copy link
Author

ShaCP commented Jul 27, 2020

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?

@07souravkunda
Copy link

Some websites don't manage etag response header.

@ttimot24
Copy link

ttimot24 commented Mar 2, 2021

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

@unparagoned
Copy link

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)
}

@jherrera
Copy link

jherrera commented Apr 9, 2022

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.

@TripleG58
Copy link

same. would like to bypass cache please

@MetaIdea
Copy link

MetaIdea commented Jun 3, 2022

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

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

@TripleG58
Copy link

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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants