[英]Hash files serve static content web server
I am writting my own static web content delivery routines. 我正在编写自己的静态Web内容传递例程。 For caching I plan to include hashes in URLs like
对于缓存,我计划在类似URL的URL中包含哈希
/static/file.MD5HASH.png /static/file.MD5HASH.png
I am developing in a static, compiled language. 我正在使用静态的编译语言进行开发。 I read https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#cachedstaticfilesstorage and https://gist.github.com/3207357
我阅读了https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#cachedstaticfilesstorage和https://gist.github.com/3207357
Now my mental problem is how to determine efficiently the hash of a file? 现在我的精神问题是如何有效地确定文件的哈希值? I will not calculate the hash upon every request to the server.
我不会根据对服务器的每个请求来计算哈希。 So I need some caching.
所以我需要一些缓存。
I could write a helping program which takes the path to the static content, recursively calculates the hash and stores the result as 我可以编写一个帮助程序,该程序采用静态内容的路径,递归地计算哈希并将结果存储为
filename.png HASH filename.png哈希
in a file called .cache.hash.lookup. 在名为.cache.hash.lookup的文件中。 This file is loaded on web server start and statet on every request so when a static file is about to be served it will look it up in the cache and if the cache is outdated, re-load the cache.
该文件在Web服务器启动时加载,并在每次请求时声明,因此当要提供静态文件时,它将在缓存中查找该文件,如果缓存已过期,请重新加载缓存。
Is this feasible? 这可行吗? Please I do not need advice how to do it using framework X as I would like to understand it and write my own routines.
请不要建议我如何使用框架X进行操作,因为我想了解它并编写自己的例程。
Reading your link, the idea there is to store multiple versions of the same resource, so adding the hash to the filename happens when you insert a new file. 阅读您的链接后,这里的想法是存储同一资源的多个版本,因此在插入新文件时会在文件名中添加哈希。
Your HTTP server can be dumb and just look up files by name. 您的HTTP服务器可能很笨,只能按名称查找文件。 (another advantage I see is you can blindly respond with "304 Not changed" to any conditional request, as the hash in the filename acts as the etag.)
(我看到的另一个优点是,您可以对任何条件请求进行盲目响应,“ 304不变”,因为文件名中的哈希充当etag。)
Or am I missing something? 还是我错过了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.