Twitter の JSONP のキャッシュ

May 23rd, 2007

Twitter の JSONP は、コールバックの関数名までキャッシュしやがります。

% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=foo' | fold -w 70 | head -n 1
foo([{"created_at":"05/22/2007 15:37:49 UTC","text":"test desu","id":7
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=bar' | fold -w 70 | head -n 1
foo([{"created_at":"05/22/2007 15:37:49 UTC","text":"test desu","id":7
%

入力が foo から bar に変わっているのに、出力の変化が無いことに注意。

% curl -s -u EMAIL:PASS -d 'status=test+desuyo' 'http://twitter.com/statuses/update.json' > /dev/null 
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=bar' | fold -w 70 | head -n 1
bar([{"created_at":"05/22/2007 15:44:45 UTC","text":"test desuyo","id"
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=foo' | fold -w 70 | head -n 1
bar([{"created_at":"05/22/2007 15:44:45 UTC","text":"test desuyo","id"
%

update でメッセージを更新すればキャッシュはクリアされるんだけど、さすがに実用的ではない。

こういうときは count をつけると、うまくキャッシュを無視してくれるようです。

% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=foo&count=20' | fold -w 70 | head -n 1
foo([{"created_at":"05/22/2007 15:44:45 UTC","text":"test desuyo","id"
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/user_timeline.json?callback=bar&count=20' | fold -w 70 | head -n 1
bar([{"created_at":"05/22/2007 15:44:45 UTC","text":"test desuyo","id"
%

friends_timeline でも同様。

% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/friends_timeline.json?callback=foo' | fold -w 70 | head -n 1
foo([{"created_at":"05/22/2007 15:49:03 UTC","text":"\u3061\u3087\u306
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/friends_timeline.json?callback=bar' | fold -w 70 | head -n 1
foo([{"created_at":"05/22/2007 15:49:03 UTC","text":"\u3061\u3087\u306
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/friends_timeline.json?callback=bar&count=20' | fold -w 70 | head -n 1
bar([{"created_at":"05/22/2007 15:49:03 UTC","text":"\u3061\u3087\u306
%

でも friends_timeline は引数として count はとらない、ので出力件数は変化しません。

% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/friends_timeline.json?callback=bar&count=20' | fold -w 70 | wc -l   
     124
% curl -s -u EMAIL:PASS 'http://twitter.com/statuses/friends_timeline.json?callback=bar&count=10' | fold -w 70 | wc -l
     124

気持ち悪い……。