Browse files

Do not let the client cache future requests

Imagine we have a client whose clock is in the future. Then when it
makes a request in which the end timestamp is in the future and we
cache it, the next client who makes a request for the same timestamp
will get the cached version. But since the cached data is much older
there is a chance meanwhile there will be changes and we will serve
the wrong data.
  • Loading branch information...
1 parent 558008c commit 6c6675763ff3c3526cc54991e3bc9ca5cf412e95 @nb nb committed Jul 4, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 liveblog.php
View
8 liveblog.php
@@ -40,6 +40,7 @@ class WPCOM_Liveblog {
static $post_id = null;
static $entries = null;
+ static $do_not_cache_response = false;
function load() {
add_action( 'init', array( __CLASS__, 'init' ) );
@@ -92,6 +93,10 @@ function handle_entries_ajax_request() {
wp_safe_redirect( get_permalink() );
}
+ if ( $end_timestamp > $current_timestamp ) {
+ self::$do_not_cache_response = true;
+ }
+
$entries = self::$entries->get_between_timestamps( $start_timestamp, $end_timestamp );
if ( !$entries ) {
self::json_return( true, '', array( 'entries' => array(), 'current_timestamp' => $current_timestamp, 'latest_timestamp' => null ) );
@@ -377,6 +382,9 @@ function json_return( $success, $message, $data = array() ) {
) );
header( 'Content-Type: application/json' );
+ if ( self::$do_not_cache_response ) {
+ nocache_headers();
+ }
echo $return;
exit;
}

0 comments on commit 6c66757

Please sign in to comment.