本篇文章由個人 一日一題 中的四個
Issue
組合而成前端
不必定,由服務器中 ETag
的生成算法決定。詳見 #112node
好比 nginx
中的 etag
由 last_modified
與 content_length
組成,而 last_modified
又由 mtime
組成linux
當編輯文件卻未更改文件內容時,mtime
也會改變,此時 etag
改變,可是文件內容沒有更改。nginx
通常會選文件的 mtime
,表示文件內容的修改時間git
nginx
也是這樣處理的,源碼見: ngx_http_static_module.cgithub
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = of.size;
r->headers_out.last_modified_time = of.mtime;
複製代碼
那爲何使用 mtime
而非 ctime
面試
在 linux
中,算法
mtime
:modified time
指文件內容改變的時間戳ctime
:change time
指文件屬性改變的時間戳,屬性包括 mtime
。而在 windows 上,它表示的是 creation time
因此 ctime
會比 mtime
要大一些,使用 stat
查看文件屬性以下c#
$ stat hello.txt
File: ‘hello.txt’
Size: 30 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 917526 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-12-10 16:15:55.253325208 +0800
Modify: 2019-12-10 16:15:52.740653330 +0800
Change: 2019-12-10 16:15:52.742653069 +0800
Birth: -
複製代碼
而 http 服務選擇 Last_Modified
時通常會選擇 mtime
windows
我是山月,你能夠添加我微信 shanyue94 與我交流