Skip to content

Commit 13a46a2

Browse files
committed
Merge pull request reactjs#37 from zpao/no-cache
Set no-cache header
2 parents 3557139 + 0894520 commit 13a46a2

File tree

5 files changed

+6
-1
lines changed

5 files changed

+6
-1
lines changed

server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
6969
}
7070

7171
w.Header().Set("Content-Type", "application/json")
72+
w.Header().Set("Cache-Control", "no-cache")
7273
io.Copy(w, bytes.NewReader(commentData))
7374

7475
case "GET":
7576
w.Header().Set("Content-Type", "application/json")
77+
w.Header().Set("Cache-Control", "no-cache")
7678
// stream the contents of the file to the response
7779
io.Copy(w, bytes.NewReader(commentData))
7880

server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ app.post('/comments.json', function(req, res) {
3333
comments.push(req.body);
3434
fs.writeFile('_comments.json', JSON.stringify(comments, null, 4), function(err) {
3535
res.setHeader('Content-Type', 'application/json');
36+
res.setHeader('Cache-Control', 'no-cache');
3637
res.send(JSON.stringify(comments));
3738
});
3839
});

server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function routeRequest()
2626
file_put_contents('_comments.json', $comments);
2727
}
2828
header('Content-Type: application/json');
29+
header('Cache-Control: no-cache');
2930
echo $comments;
3031
break;
3132
default:

server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def comments_handler():
2626
with open('_comments.json', 'w') as file:
2727
file.write(json.dumps(comments, indent=4, separators=(',', ': ')))
2828

29-
return Response(json.dumps(comments), mimetype='application/json')
29+
return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache'})
3030

3131
if __name__ == '__main__':
3232
app.run(port=3000)

server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# always return json
2929
res['Content-Type'] = 'application/json'
30+
res['Cache-Control'] = 'no-cache'
3031
res.body = JSON.generate(comments)
3132
end
3233

0 commit comments

Comments
 (0)