Ben*_*Ben 25 django caching django-staticfiles django-pipeline
基本上,缓存清除文件上的哈希不会更新.
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
PIPELINE_JS = {
'main.js': {
'output_filename': 'js/main.min.js',
'source_filenames': [
'js/external/underscore.js',
'js/external/backbone-1.0.0.js',
'js/external/bootstrap-2.2.0.min.js',
]
}
}
Run Code Online (Sandbox Code Playgroud)
当我第一次运行该collectstatic命令时,它正确地创建了一个名为""的缓存清除文件main.min.d25bdd71759d.js
但是,当我运行该命令时,它无法在后处理阶段覆盖该缓存文件(并更新哈希).
它不断更新" main.min.js",这main.min.js与我的文件系统是最新的.但是,未创建新的缓存文件.即使底层main.min.js文件已更改,它也会保留相同的旧哈希.
当我手动删除AWS上的缓存文件时,我会从collectstatic详细程度设置为3的运行中收到以下消息:
Post-processed 'js/main.min.js' as 'js/main.min.d25bdd71759d.js
Run Code Online (Sandbox Code Playgroud)
settings.DEBUG 被设置为 False
为什么哈希不会更新?
尝试使用清单存储来代替:
\n\nclass S3PipelineManifestStorage(PipelineMixin, ManifestFilesMixin, S3BotoStorage):\n pass\nRun Code Online (Sandbox Code Playgroud)\n\n根据此处的 django 文档https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#cachedstaticfilesstorage不建议使用CachedStaticFilesStorage.
您的静态文件的文件名可能会被缓存。所以使用清单文件。
\n\n\n\n\nCachedStaticFilesStorage 不推荐 \xe2\x80\x99 几乎在所有情况下 \xe2\x80\x93 ManifestStaticFilesStorage 是更好的选择。使用 CachedStaticFilesStorage 时会出现一些性能损失,因为缓存未命中需要在运行时对文件进行哈希处理。远程文件存储需要多次往返才能在缓存未命中时对文件进行哈希处理,因为需要多次文件访问才能确保在嵌套文件路径的情况下文件哈希值是正确的。
\n
请注意,这也记录在 django-pipelines 中 http://django-pipeline.readthedocs.io/en/latest/storages.html#using-with-other-storages
\n| 归档时间: |
|
| 查看次数: |
1481 次 |
| 最近记录: |