Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Do 19.03.09 20:38 
Hi!

Ich bastle grad mal etwas mit Ajax rum, und laufe da ständig in komische Caching-Probleme. Und zwar rufe ich (mit Prototype) per Ajax.Request eine Datei ab. Wirklich eine Datei, kein PHP- oder ähnliches Script.
Das Problem ist: wenn ich das normal mache, wird das Ding nur einmal abgerufen. Danach wird der XMLHTTPRequest direkt aus dem Cache bedient, ohne nochmal zu revalidaten und ggf auf das 304 zu warten. Ist doof, wenn sich die Datei geändert hat (ich also weiter programmiert hab^^). Ich muss also das Caching ausschalten.
Das geht auch, indem ich im Request ein "If-modified-since: $(Zeitpunkt weit in der Vergangenheit)" mitschicke. Ist nur nicht ganz sinn der Sache, denn wenn die Datei gleich ist, darf er sie gerne Cachen bzw. soll das auch.

Wäre das jetzt ein Script wärs ja kein Thema, dann könnte ich den Client ja per Header zum revalidieren verpflichten...

Irgend ne Idee, wie man das lösen könnte?

Im Grunde soll er sich nur so verhalten wie wenn es ein normaler Webseitenaufruf wäre und den Cache auch mal überprüfen.


Danke schonmal,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Di 24.03.09 17:05 
Hast du Zugriff auf den Server? Wenn ja: Etag ist das richtige für dich. Bei dir wird scheinbar der max-age-Header gesendet. Ist das möglich?
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 24.03.09 17:31 
Ja, auch ETags werden mitgesendet und ignoriert.

Ich könnte auch ein 'if-none-match:' mitsenden, mir gehts nur darum, den FF reinzulegen so dass er den Request auch wirklich ausführt. Das scheint nur zu gehen, indem man *irgendwas* Cache-Betreffendes in den Header schreibt.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 25.03.09 00:01 
Hast du Demo-Code? Also php + FF-Bsp?
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 25.03.09 00:46 
Glaubs mir, da gibts keine PHP ;)

Und ansonsten reicht das:
1. Prototype einbinden (ich hab die aktuelle, also 1.6.0.3)
ausblenden 2. Ajax.Request erzeugen:
1:
2:
3:
4:
5:
6:
7:
8:
9:
new Ajax.Request('some/file.txt', {
  method:'get',
  asynchronous: false,
  evalJS: false,
  requestHeaders: [ 'if-modified-since''Sat, 1 Jan 2000 00:00:00 GMT'],
  onSuccess: function(response)  {
     //whatever
  }
});

3. Rumprobieren...

Mal mit und mal ohne die Headers probieren und dann im Network-Tab vom Firebug gucken was passiert. Oder eben nicht passiert: das erste mal nach Cache-Löschung klappt immer normal, danach wird der Request gar nicht mehr abgeschickt sondern wird direkt ausm Cache bedient. Alternativ zum Header könnte ich auch einen zufälligen Query-String an die URL anhängen, aber das ist ja auch nicht Sinn der Sache.

EDIT: interessant. Es hängt auch noch vom content-type der Daten ab, oder so.
Ich hab mal ein kleines Test-Projekt geschraubt, hier ist es. Das ganze gibts im Anhang nochmal als zip.

Man sieht, dass das Caching-Verhalten relativ chaotisch ist. Das einzige was geht, ist das "immer neu laden" wenn man den Cache ganz ausschaltet, sei es per WebDeveloperToolbar oder Request-Header ;)
Einloggen, um Attachments anzusehen!
_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 25.03.09 08:45 
Eigentlich doch ganz normal, dass eine Textdatei nur aus dem Cache geladen wird. Normalerweise ändern sich Textdateien ja auch nicht. Wie sieht es bei XML aus?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)