本文整理匯總了Python中pyramid.response.FileResponse.cache_expires方法的典型用法代碼示例。如果您正苦於以下問題:Python FileResponse.cache_expires方法的具體用法?Python FileResponse.cache_expires怎麽用?Python FileResponse.cache_expires使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyramid.response.FileResponse
的用法示例。
在下文中一共展示了FileResponse.cache_expires方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: static_asset_response
# 需要導入模塊: from pyramid.response import FileResponse [as 別名]
# 或者: from pyramid.response.FileResponse import cache_expires [as 別名]
def static_asset_response(request, asset):
resolver = AssetResolver()
descriptor = resolver.resolve(asset)
if not descriptor.exists():
raise HTTPNotFound(request.url)
path = descriptor.abspath()
response = FileResponse(path, request)
zip_response = False
for ending in ['.css', '.js', '.coffee', '.html', '.ttf']:
if path.endswith(ending):
zip_response = True
if zip_response:
response.encode_content()
for ending in ['.css', '.js']:
# one day for css and js
if path.endswith(ending):
response.cache_expires(3600*24)
response.cache_control.public = True
if path.endswith('.ttf'):
# one year for fonts
response.cache_expires(3600*24*365)
response.cache_control.public = True
return response