本篇文章由個人 一日一題 中的四個
Issue
組合而成前端
不必定,由服務器中 ETag
的生成算法決定。詳見 #112node
好比 nginx
中的 etag
由 last_modified
與 content_length
組成,而 last_modified
又由 mtime
組成linux
當編輯文件卻未更改文件內容時,mtime
也會改變,此時 etag
改變,可是文件內容沒有更改。nginx
通常會選文件的 mtime
,表示文件內容的修改時間git
nginx
也是這樣處理的,源碼見: ngx_http_static_module.c程序員
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
github
在 linux
中,面試
mtime
:modified time
指文件內容改變的時間戳ctime
:change time
指文件屬性改變的時間戳,屬性包括 mtime
。而在 windows 上,它表示的是 creation time
因此 ctime
會比 mtime
要大一些,使用 stat
查看文件屬性以下算法
$ 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
c#
我是山月,一個喜歡跑步與登山的程序員,我會按期分享全棧文章在我的公衆號中。若是你對全棧面試,前端工程化,graphql,devops,我的服務器運維以及微服務感興趣的話,能夠關注我