我有一個應用程序與Python瓶,我想添加緩存控制在靜態文件。如果我做錯了什麼,我對此很新,所以請原諒我。Python瓶和緩存控制
下面是函數,我如何提供靜態文件:
@bottle.get('/static/js/<filename:re:.*\.js>')
def javascripts(filename):
return bottle.static_file(filename, root='./static/js/')
要添加緩存控制我已經包含了一個多線(我看到它的教程)
@bottle.get('/static/js/<filename:re:.*\.js>')
def javascripts(filename):
bottle.response.headers['Cache-Control'] = 'public, max-age=604800'
return bottle.static_file(filename, root='./static/js/')
但是,當我檢查了Chrome上的開發人員工具的標題:我有Cache-Control:max-age=0
或Cache-Control:no-cache
嘗試使用''response.set_header的(),而不是'response.headers'因爲他們在[文檔]說(HTTP:// bottlepy。組織/文檔的/ dev/tutorial.html?突顯=緩存控制)。像這樣''response.set_header('Cache-Control','max-age = 3600,public')' – doru
@doru我已經嘗試過了,但是在Chrome開發者工具的網絡選項卡中我有同樣的事情(Cache-控制:最大年齡= 0)。並且每個靜態文件似乎都會在每次刷新時加載 – Sfinos
請使用「wget」或「curl」代替Chrome,並讓我們知道您看到的內容。 –