Alexander Mills
Alexander Mills

Reputation: 100000

Prevent caching for certain API route - ETag?

I am confused why I am getting this:

GET /api/v1/changelog/json 304 50.967 ms - -

It looks like the browser is caching the result...but this a JSON request, that should never be cached.

I guess I need to change a header so it uses the 'application/json' header? That will prevent caching?

But the thing is, I already have that header:

     getGitLog: function () {
        return $http({
          method: 'GET',
          url: `/api/v1/changelog/json`,
          data: {},
          headers: {
            'Content-Type': 'application/json'
          },
        })
     },

Upvotes: 0

Views: 950

Answers (2)

metinata
metinata

Reputation: 156

You can use cache: false option like this:

getGitLog: function () {
    return $http({
      method: 'GET',
      url: `/api/v1/changelog/json`,
      cache: false,
      data: {},
      headers: {
        'Content-Type': 'application/json'
      },
    })
 },

Upvotes: 1

Alexander Mills
Alexander Mills

Reputation: 100000

It appears that disabling Etag's was the solution. With Node.js Express, that would be:

app.disable('etag');

Upvotes: 0

Related Questions