In debug:
I run ng serve
on my angular project, make the request and receive the updated values
In production
I update de files of the API and the angular project, make the request and receive old data. If I open the API link in a new tab I get the updated values, even the files in the server are acting like that but if I open their links, even when deleted, I still can access it.
Even when I deleted all the values in a table I still get outdated data
Both production and debug access the same database
Technologies:
- Front-end: Angular
- Back-end: Flask
What I’ve tried:
- Set @@AUTOCOMMIT to 1
- Change cache in order to not be saved
Here is the code of one endpoint:
JavaScript
x
33
33
1
@app.route('/api/produtos/categoria/<categoria>', methods=['GET'])
2
@cross_origin(supports_credentials=True)
3
def getProdutosByCategoria(categoria):
4
print(request.headers)
5
if request.method == 'GET':
6
sql = "SELECT p.id, p.data_cadastro, p.nome, p.certificado_aprovacao, p.data_validade, p.fabricante, p.complemento, p.tamanho, p.tipo, p.preco, p.quantidade_estoque, cp.nome, p.link_imagem FROM produtos p JOIN categoria_produtos cp ON p.categoria_id = cp.id WHERE a_venda = 1 AND categoria_id = %s" % (categoria)
7
8
try:
9
mydb.commit()
10
cursor.execute(sql)
11
data = cursor.fetchall()
12
result = []
13
for item in data:
14
result.append({
15
"Id": item[0],
16
"DataCadastro": item[1],
17
"Nome": item[2],
18
"CertificadoAprovação": item[3],
19
"DataValidade": item[4],
20
"Fabricante": item[5],
21
"Complemento": item[6],
22
"Tamanho": item[7],
23
"Tipo": item[8],
24
"Preco": item[9],
25
"QuantidadeEstoque": item[10],
26
"Categoria": item[11],
27
'Imagem': item[12]
28
})
29
except:
30
return {'Status': 'erro', "Message": "Não foi possível carregar os produtos"}
31
else:
32
return {'Status': 'success', "Message": "Produtos carregados com sucesso", "Data": result}
33
Caching system
this is added after every request
JavaScript
1
11
11
1
@app.after_request
2
def after_request(response):
3
response.headers.add('Access-Control-Allow-Origin', 'http://censored-domain/')
4
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
5
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
6
response.headers.add('Access-Control-Allow-Credentials', 'true')
7
response.cache_control.max_age = 60
8
if 'Cache-Control' not in response.headers:
9
response.headers['Cache-Control'] = 'no-store'
10
return response
11
Advertisement
Answer
Solved by removing cache
My thought:
Since in development I’ll have to make the same request many times, I removed cache from the Angular project and will only put it back when it is in production.
Thanks for the help