Push-Nachrichten von MacTechNews.de
Würden Sie gerne aktuelle Nachrichten aus der Apple-Welt direkt über Push-Nachrichten erhalten?
Forum>Netzwerke>Bug in Apache Server?: Negativer Wert bei max-age

Bug in Apache Server?: Negativer Wert bei max-age

dom_beta22.06.1219:46

Hallo,

wenn ich "meine" Seite teste, liefert er mir bei max-age einen negativen Wert zurück.

Ist das normal oder handelt es sich hierbei um einen Bug in dem Apache Webserver?



.htaccess:
ExpiresDefault "modification"
ExpiresByType image/gif "modification plus 2 hours"
ExpiresByType image/jpg "modification plus 2 hours"
ExpiresByType image/png "modification plus 2 hours"

Soweit ich das verstanden habe, bedeutet das, wenn eine Datei
verändert wurde, daß diese sofort aktualisiert wird. Jedenfalls; mit
ein paar Testdateien funktioniert dies zuverlässig: Der Browser
aktualisiert die Seite sofort.

Ergebnis beim Testen mit http://www.webconfs.com/http-header-check.php
HTTP/1.1 200 OK =>
Date => Fri, 22 Jun 2012 09:59:35 GMT
Server => Apache/2.2.0 (Fedora)
Last-Modified => Fri, 15 Jun 2012 23:06:18 GMT
ETag => "674035-751-dd204e80"
Accept-Ranges => bytes
Content-Length => 1873
Cache-Control => max-age=-557597
Expires => Fri, 15 Jun 2012 23:06:18 GMT
Connection => close
Content-Type => text/html; charset=UTF-8
„...“
0

Kommentare

sierkb22.06.1221:23
Wenn ich mich nicht irre und mich nicht verrechnet habe, stimmt die Zahl. Rechne selbst nach.

Apache HTTP Server Version 2.2 documentation: Apache Module mod_expires: ExpiresDefault Directive :
ExpiresDefault Directive

This directive sets the default algorithm for calculating the expiration time for all documents in the affected realm. It can be overridden on a type-by-type basis by the ExpiresByType directive. See the description of that directive for details about the syntax of the argument, and the alternate syntax description as well.

und

ExpiresByType Directive :
ExpiresByType Directive

This directive defines the value of the Expires header and the max-age directive of the Cache-Control header generated for documents of the specified type (e.g., text/html). The second argument sets the number of seconds that will be added to a base time to construct the expiration date. The Cache-Control: max-age is calculated by subtracting the request time from the expiration date and expressing the result in seconds.

The base time is either the last modification time of the file, or the time of the client's access to the document.
Which should be used is specified by the <code> field; M means that the file's last modification time should be used as the base time, and A means the client's access time should be used.

The difference in effect is subtle. If M is used, all current copies of the document in all caches will expire at the same time, which can be good for something like a weekly notice that's always found at the same URL. If A is used, the date of expiration is different for each client; this can be good for image files that don't change very often, particularly for a set of related documents that all refer to the same images (i.e., the images will be accessed repeatedly within a relatively short timespan).

Example:
# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType image/gif A2592000
# HTML documents are good for a week from the
# time they were changed
ExpiresByType text/html M604800

Note that this directive only has effect if ExpiresActive On has been specified. It overrides, for the specified MIME type only, any expiration date set by the ExpiresDefault directive.

You can also specify the expiration time calculation using an alternate syntax, described earlier in this document.
[..]

Du hast in Deiner .htaccess u.a. und zuoberst angegeben:
ExpiresDefault "modification"

Diese Direktive wird also auf alle Dokumente (wie z.B. das ausgelieferte HTML-Dokument) angewendet basierend auf dem Modifikationsdatum der betreffenden Datei, da Deine ExpiresByType-Angaben nur bei Bildern (image/gif, image/jpg, image/png) matchen bzw. für diese vorgesehen sind.

Der obige HTTP-Response gibt für die betreffende HTML-Datei u.a. Folgendes aus:
Expires => Fri, 15 Jun 2012 23:06:18 GMT als den Zeitpunkt, an dem dieses Dokument zuletzt geändert wurde (modification time). Du hast mit der Direktive ExpiresDefault "modification" festgelegt, dass jenes Modifikationsdatum der standardmäßige Expires-Zeitpunkt sein soll, also standardmäßig alle Dokumente (mit Ausnahme von bestimmten Bilder-typen, für die Du gesonderte Anweisungen gemacht hast) zum Zeitpunkt ihres Abrufs als veraltet zu gelten haben, da deren Gültigkeit gleich deren Modifikationsdatum sein soll und dieses Datum zum Zeitpunkt des Abrufs eigentlich immer in der Vergangenheit liegt bzw. nur liegen kann (also nur ein negativer Zeitwert sein kann, da das Modifikationsdatum auf dem Zeitstrahl eben zurückliegt und nicht vor uns in der Zukunft liegt -- daher das Minuszeichen. Läge der Expires-Zeitpunkt in der Zukunft (z.B. ein paar Stunden, Tage, Wochen, Monate, Jahre), dann käme dabei ein positiver Zahlenwert heraus, das ist hier aber von Dir nicht gewünscht und nicht gegeben).

Nun rechne mal zurück bzw. vor in die Zukunft, ausgehend vom Modifikationsdatum der Datei, nämlich Fri, 15 Jun 2012 23:06:18 GMT. Wieviele Sekunden sind das bis zum Zeitpunkt des Aufrufs dieser HTML-Datei (Fri, 22 Jun 2012 09:59:35 GMT)?
Das sind nicht zufällig exakt jene 557597 Sekunden, die bei Dir im Header als Cache-Control => max-age=-557597 drinstehen?
Und da das Modifikationsdatum der HTML-Datei eben bereits 6 Tage bzw. 557597 Sekunden in der Vergangenheit liegt, ist's natürlich eine Zahl mit negativem Vorzeichen, die da nun unter max-age steht. Oder anders ausgedrückt: die Aktualität dieser HTML-Seite ist seit 6 Tagen bzw. genau 557597 Sekunden abgelaufen, hat deshalb einen negativen Wert für max-age und dürfte in der Folge nicht mehr gecachet, sondern sofort neu angefordert werden, weil Du als zeitliche Grenze per Direktive ExpiresDefault "modification" das betreffende Modifikationsdatum der Datei angegeben hast, ihr also null Sekunden Gültigkeit zugestanden hast, damit sie stets erneut angefordert (weil der Abrufzeitpunkt wohl immer weiter fortgeschritten sein wird als das von Dir per Direktive zugrundegelegte Modifikationsdatum) wird und nicht aus dem Cache geholt wird.
0
dom_beta22.06.1221:57

Hallo Sierk,

die Idee hinter dieser Einstellung soll sein, daß wenn die Datei geändert wurde, soll er sie erneut vom Server holen. Wenn sie nicht verändert wurde, kann er sie aus dem Cache holen, weil dann eine Aktualisierung nicht sinnvoll ist, denn wenn nichts verändert wurde, macht eine Aktualisierung keinen Sinn.

Deswegen auch ExpiresDefault "modification", sofern dies überhaupt die richtige Anweisung ist. Ist sie das überhaupt?
„...“
0

Kommentieren

Diese Diskussion ist bereits mehr als 3 Monate alt und kann daher nicht mehr kommentiert werden.