Expires¡¢Cache-Control¡¢Last-Modified¡¢ETagÊÇRFC 2616£¨HTTP/1.1£©ÐÒéÖкÍÍøÒ³»º´æÏà¹ØµÄ¼¸¸ö×ֶΡ£Ç°Á½¸öÓÃÀ´¿ØÖÆ»º´æµÄʧЧÈÕÆÚ£¬ºóÁ½¸öÓÃÀ´ÑéÖ¤ÍøÒ³µÄÓÐЧÐÔ¡£Òª×¢ÒâµÄÊÇ£¬HTTP/1.0ÓÐÒ»¸ö¹¦ÄܱȽÏÈõµÄ»º´æ¿ØÖÆ»úÖÆ£ºPragma£¬Ê¹ÓÃHTTP/1.0µÄ»º´æ½«ºöÂÔExpiresºÍCache-ControlÍ·¡£ÎÒÃÇÕâÀïÒÔApache2.0·þÎñÆ÷ΪÀý£¬Ö»ÌÖÂÛHTTP/1.1ÐÒé¡£ Expires Expires×Ö¶ÎÉùÃ÷ÁËÒ»¸öÍøÒ³»òURLµØÖ·²»ÔÙ±»ä¯ÀÀÆ÷»º´æµÄʱ¼ä£¬Ò»µ©³¬¹ýÁËÕâ¸öʱ¼ä£¬ä¯ÀÀÆ÷¶¼Ó¦¸ÃÁªÏµÔʼ·þÎñÆ÷¡£RFC¸æËßÎÒÃÇ£º¡°ÓÉÓÚÍƶϵÄʧЧʱ¼äÒ²Ðí»á½µµÍÓïÒå͸Ã÷¶È£¬Ó¦¸Ã±»½÷É÷ʹÓã¬Í¬Ê±ÎÒÃǹÄÀøÔʼ·þÎñÆ÷¾¡¿ÉÄÜÌṩȷÇеÄʧЧʱ¼ä¡£¡± ¶ÔÓÚÒ»°ãµÄ´¿¾²Ì¬Ò³Ã棬Èçhtml¡¢gif¡¢jpg¡¢css¡¢js£¬Ä¬ÈÏ°²×°µÄApache·þÎñÆ÷£¬²»»áÔÚÏìӦͷÌí¼ÓÕâ¸ö×ֶΡ£Firefoxä¯ÀÀÆ÷½ÓÊܵ½ÏàÓ¦ºó£¬Èç¹û·¢ÏÖûÓÐExpires×ֶΣ¬ä¯ÀÀÆ÷¸ù¾ÝÎļþµÄÀàÐͺ͡°Last-Modified¡±×Ö¶ÎÀ´ÍƶϳöÒ»¸öºÏÊʵÄʧЧʱ¼ä£¬²¢´æ´¢ÔÚ¿Í»§¶Ë¡£ÍƲâ³öµÄʱ¼äÒ»°ãÊǽÓÊܵ½ÏìӦʱ¼äºóµÄÈýÌì×óÓÒ¡£ ApacheµÄexpires_moduleÄ£¿é¿ÉÒÔÔÚHttpÏìӦͷ²¿×Ô¶¯¼ÓÉÏExpires×ֶΡ£ÔÚApacheµÄhttpd.confÎļþÖнøÐÐÈçÏÂÅäÖ㺠#ÆôÓÃexpires_moduleÄ£¿é LoadModule expires_module modules/mod_expires.so # ÆôÓÃÓÐЧÆÚ¿ØÖÆ ExpiresActive On # GIFÓÐЧÆÚΪ1¸öÔ ExpiresByType image/gif A2592000 # HTMLÎĵµµÄÓÐЧÆÚÊÇ×îºóÐÞ¸Äʱ¿ÌºóµÄÒ»ÐÇÆÚ ExpiresByType text/html M604800 #ÒÔϵĺ¬ÒåÀàËÆ ExpiresByType text/css ¡°now plus 2 month¡± ExpiresByType text/js ¡°now plus 2 day¡± ExpiresByType image/jpeg ¡°access plus 2 month¡± ExpiresByType image/bmp ¡°access plus 2 month¡± ExpiresByType image/x-icon ¡°access plus 2 month¡± ExpiresByType image/png ¡°access plus 2 month¡± ¶ÔÓÚ¶¯Ì¬Ò³Ã棬Èç¹ûÔÚÒ³ÃæÄÚ²¿Ã»ÓÐͨ¹ýº¯ÊýÇ¿ÖƼÓÉÏExpires£¬ÀýÈçheader(¡±Expires: ¡± . gmdate(¡±D, d M Y H:i:s¡±) . ¡± GMT¡±)£¬Apache·þÎñÆ÷»á°ÑWed, 11 Jan 1984 05:00:00 GMT ×÷ΪExpires×Ö¶ÎÄÚÈÝ£¬·µ»Ø¸øä¯ÀÀÆ÷¡£¼´ÈÏΪ¶¯Ì¬Ò³Ãæ×ÜÊÇʧЧµÄ¡£¶øä¯ÀÀÆ÷ÈÔÈ»»á±£´æÒѾʧЧµÄ¶¯Ì¬Ò³Ãæ¡£ ¿ÉÒÔ·¢ÏÖFirefoxä¯ÀÀÆ÷×ÜÊÇ»º´æËùÓÐÒ³Ã棬²»¹ÜʧЧ¡¢²»Ê§Ð§»¹ÊÇûÓÐÉùÃ÷ʧЧʱ¼ä¡£¼´Ê¹»º´æÖÐÉùÃ÷ÁËÒ»¸öÍøÒ³µÄʵЧÈÕÆÚÊÇ1970-01-01 08:00:00£¬ä¯ÀÀÆ÷ÈÔÈ»»á·¢Ë͸ÃÎļþÔÚ»º´æÖеÄLast-ModifiedºÍETag×ֶΡ£ Èç¹ûÔÚ·þÎñÆ÷¶ËÑé֤ͨ¹ý£¬·µ»Ø304״̬£¬ä¯ÀÀÆ÷¾Í»¹»áʹÓô˻º´æ¡£
Cache-Control Cache-Control×Ö¶ÎÖпÉÒÔÉùÃ÷¶àЩԪËØ£¬ÀýÈçno-cache, must-revalidate, max-age=0µÈ¡£ÕâЩԪËØÓÃÀ´Ö¸Ã÷Ò³Ãæ±»»º´æ×î´óʱÏÞ£¬ÈçºÎ±»»º´æµÄ£¬ÈçºÎ±»×ª»»µ½ÁíÒ»¸ö²»Í¬µÄý½é£¬ÒÔ¼°ÈçºÎ±»´æ·ÅÔÚ³Ö¾Ãý½éÖеġ£µ«ÊÇÈκÎÒ»¸öCache-ControlÖ¸Á²»Äܱ£Ö¤Òþ˽ÐÔ»òÕßÊý¾ÝµÄ°²È«ÐÔ¡£¡°private¡±ºÍ¡°no-store¡±Ö¸Áî¿ÉÒÔΪÒþ˽ÐԺͰ²È«ÐÔ·½ÃæÌṩһЩ°ïÖú£¬µ«ÊÇËûÃDz¢²»ÄÜÓÃÓÚÌæ´úÉí·ÝÑéÖ¤ºÍ¼ÓÃÜ¡£ ApacheµÄmod_cern_metaÄ£¿éÔÊÐíÎļþ¼¶HttpÏìӦͷ²¿µÄ¿ØÖÆ£¬Í¬Ê±ËüÒ²¿ÉÒÔÅäÖÃCache-ControlÍ·£¨»òÈκÎÆäËûÍ·£©¡£ÏìӦͷÎļþÊÇ·ÅÔÚÔʼĿ¼µÄ×ÓĿ¼ÖУ¬¸ù¾ÝÔʼÎļþÃûËùÃüÃûµÄÒ»¸öÎļþ¡£¾ßÌåÓ÷¨Çë²ÎÔÄApacheµÄ¹Ù·½ÍøÕ¾¡£ ÆäÖÐCache-Control : max-age±íʾʧЧÈÕÆÚ¡£Èç¹ûûÓÐÆô¶¯mod_cern_metaÄ£¿é£¬Apache·þÎñÆ÷»á°ÑExpires×Ö¶ÎÖеÄÈÕÆÚ»»Ëã³ÉÒÔÃëΪµ¥Î»µÄÒ»¸ödeltaÖµ£¬¸³Öµ¸ømax-age¡£Èç¹ûÆô¶¯mod_cern_metaÄ£¿é£¬²¢ÇÒÅäÖÃÁËmax-ageÖµ£¬Apache»á½«Õâ¸ö¸²¸ÇExpires×ֶΡ£Í¬Ê±£¬max-ageÒþº¬ÁËCanche-Control: public¡£ÕâÑùä¯ÀÀÆ÷½ÓÊܵ½µÄCache-Control : max-ageºÍExpiresÖµ¾ÍÊÇÒ»Öµġ£ Èç¹ûʧЧÈÕÆÚCache-Control : max-ag=0»òÕßÊǸºÖµ£¬ä¯ÀÀÆ÷»áÔÚ¶ÔÓ¦µÄ»º´æÖаÑExpiresÉèÖÃΪ1970-01-01 08:00:00¡£
Last-Modified Last-ModifiedºÍETagÊÇÌõ¼þÇëÇó(Conditional Request)Ïà¹ØµÄÁ½¸ö×ֶΡ£Èç¹ûÒ»¸ö»º´æÊÕµ½ÁËÕë¶ÔÒ»¸öÒ³ÃæµÄÇëÇó£¬Ëü·¢ËÍÒ»¸öÑéÖ¤ÇëÇóѯÎÊ·þÎñÆ÷Ò³ÃæÊÇ·ñÒѾ¸ü¸Ä£¬ÔÚHTTPÍ·ÀïÃæ´øÉÏ¡±ETag¡±ºÍ¡±If Modify Since¡±Í·¡£·þÎñÆ÷¸ù¾ÝÕâЩÐÅÏ¢ÅжÏÊÇ·ñÓиüÐÂÐÅÏ¢£¬Èç¹ûûÓУ¬¾Í·µ»ØHTTP 304£¨Not Modify£©£»Èç¹ûÓиüУ¬·µ»ØHTTP 200ºÍ¸üеÄÒ³ÃæÄÚÈÝ£¬²¢ÇÒЯ´øеġ±ETag¡±ºÍ¡±Last-Modified¡±¡£ ʹÓÃÕâ¸ö»úÖÆ£¬Äܹ»±ÜÃâÖظ´·¢ËÍÎļþ¸øä¯ÀÀÆ÷£¬²»¹ýÈÔÈ»»á²úÉúÒ»¸öHTTPÇëÇó¡£ Ò»°ã´¿¾²Ì¬Ò³Ãæ±¾Éí¶¼»áÓÐLast-ModifiedÐÅÏ¢£¬Apache·þÎñÆ÷»á¶ÁÈ¡Ò³ÃæÎļþÖеÄLast-ModifiedÐÅÏ¢£¬²¢Ìí¼Óµ½httpÏìӦͷ²¿¡£ ¶ÔÓÚ¶¯Ì¬Ò³Ã棬Èç¹ûÔÚÒ³ÃæÄÚ²¿Ã»ÓÐͨ¹ýº¯ÊýÇ¿ÖƼÓÉÏLast-Modified£¬ÀýÈçheader(¡±Last-Modified: ¡± . gmdate(¡±D, d M Y H:i:s¡±) . ¡± GMT¡±)£¬Apache·þÎñÆ÷»á°Ñµ±Ç°Ê±¼ä×÷ΪLast-Modified£¬·µ»Ø¸øä¯ÀÀÆ÷¡£ ÎÞÂÛÊÇ´¿¾²Ì¬Ò³Ã滹ÊǶ¯Ì¬Ò³Ã棬Firefoxä¯ÀÀÆ÷ÇÉÃîµØ°´ÕÕ½ÓÊܵ½·þÎñÆ÷ÏìÓ¦µÄʱ¼äÉèÖûº´æÒ³ÃæµÄLast-Modified£¬¶ø²»ÊÇ°´ÕÕhttpÏìӦͷ²¿ÖеÄLast-Modified×ֶΡ£ ETag ¼ÈÈ»ÓÐÁËLast-Modified£¬ÎªÊ²Ã´»¹ÒªÓÃETag×Ö¶ÎÄØ£¿ÒòΪÈç¹ûÔÚÒ»ÃëÖÓÖ®ÄÚ¶ÔÒ»¸öÎļþ½øÐÐÁ½´Î¸ü¸Ä£¬Last-Modified¾Í»á²»ÕýÈ·¡£Òò´Ë£¬HTTP/1.1ÀûÓÃEntity TagÍ·ÌṩÁ˸ü¼ÓÑϸñµÄÑéÖ¤¡£ Apache·þÎñÆ÷ĬÈÏÇé¿öÏ£¬»á¶ÔËùÓеľ²Ì¬¡¢¶¯Ì¬ÎļþµÄÏìӦͷÌí¼ÓETag×ֶΡ£ ÔÚApacheµÄhttpd.confÎļþÖпÉÒÔͨ¹ýFileETagÖ¸ÁîÅäÖøÃÑ¡Ïî¡£FileETagÖ¸ÁîÅäÖÃÁ˵±ÎĵµÊÇ»ùÓÚÒ»¸öÎļþʱÓÃÒÔ´´½¨Etag£¨entity tag£©ÏìӦͷµÄÎļþµÄÊôÐÔ¡£ÔÚApache 1.3.22¼°ÒÔÇ°£¬ETagµÄÖµÊǶÔÎļþµÄË÷Òý½Ú£¨INode£©£¬´óС£¨Size£©ºÍ×îºóÐÞ¸Äʱ¼ä£¨MTime£©½øÐÐHashºóµÃµ½µÄ¡£ Èç¹ûÒ»¸öĿ¼µÄÅäÖðüº¬ÁË¡®FileETag INode MTime Size¡¯¶øÆäÒ»¸ö×ÓĿ¼°üº¬ÁË¡®FileETag -INode¡¯ÄÇôÕâ¸ö×ÓĿ¼µÄÉèÖ㨲¢»á±»ÆäÏÂÈκÎûÓнøÐи²¸ÇµÄ×ÓĿ¼¼Ì³Ð£©½«µÈ¼ÛÓÚ¡®FileETag MTime Size¡¯¡£ ÔÚ¶ą̀¸ºÔØƽºâµÄ·þÎñÆ÷»·¾³Ï£¬Í¬Ò»¸öÎļþ»áÓв»Í¬µÄetag»òÕßÎļþÐÞ¸ÄÈÕÆÚ£¬ä¯ÀÀÆ÷ÿ´Î¶¼»áÖØÐÂÏÂÔØ¡£ÉèÖá®FileETag None¡¯¿ÉÒÔʹÏìӦͷ²»ÔÙ°üº¬ETag×ֶΡ£
|