[PYTHON] About HTTP cache when developing REST API-based web application [using GCP]

Overview

I am developing the server side with Python (Flask) on Cloud run and the client side with Javascript (Vue.js) on Firebase. Python mainly reads and writes Firestore data. At this time, I encountered the following two issues.

  1. I am making a GET request, but I am making an OPTIONS request (check with a browser) --The GET request hasn't arrived in Cloud run, but a response is returned. At this time, even if the contents of Firestore are changed by PUT etc., the response of the GET request is the contents of the previous Firestore.

This article describes these causes and countermeasures.

"About 1

For 1, the OPTIONS request is called a preflight request, and if it's not a simple request, it seems to be a CORS request to see if the CORS protocol is understood. This can be eliminated by reviewing the request settings on the client side (in the REST API, there may be an Authentication header, so it may be skipped in many cases). For pre-flight requests, please refer to the following sites. After all, this wasn't a problem, so that's it.

--Cross-origin resource sharing (CORS): https://developer.mozilla.org/ja/docs/Web/HTTP/CORS )

About "2."

This is due to the HTTP cache. ** When the response was generated on the server side, it was because I did not set the "Cache-control header" related to the HTTP cache **. As a result, the request did not originally go to the Cloud run side, and the HTTP cache in Firebase was responded to the client side. There is no problem with the first GET communication after deploying, but even if you change the contents of Firestore after that, the second and subsequent GET communication will be the same as the first content.

--HTTP cache: [https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=ja](https://developers.google.com/web/fundamentals/ performance / optimizing-content-efficiency / http-caching? hl = ja) --HTTP Cache (MDN web docs): https://developer.mozilla.org/ja/docs/Web/HTTP/Caching

in conclusion

Perhaps because it is too common sense of the web shop, there was not much article like that, so I wrote it as a memorandum.

Recommended Posts

About HTTP cache when developing REST API-based web application [using GCP]
Web application using Bottle (1)
WEB application development using django-Development 1-
Proxy measures when using WEB API
Creating a web application using Flask ②
WEB application development using Django [Application addition]
Creating a web application using Flask ①
Creating a web application using Flask ③
Creating a web application using Flask ④