Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Use etags for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Apr 23, 2012
1 parent f437111 commit e77b204
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion json.php
Expand Up @@ -83,7 +83,9 @@ function process_json($filename, $last_data) {
$ret["data"] = process_json($filename, $last_data);
$ret["status"] = "success";

echo json_encode($ret);
http_cache_etag();
http_send_content_type("application/json");
http_send_data(json_encode($ret));

// Update statistics
$redis->incr("stats:web:json:processed");
Expand Down
4 changes: 3 additions & 1 deletion sources/json.php.html
Expand Up @@ -91,7 +91,9 @@
<span class="hl kwc">$ret</span><span class="hl opt">[</span><span class="hl str">&quot;data&quot;</span><span class="hl opt">] =</span> <span class="hl kwd">process_json</span><span class="hl opt">(</span><span class="hl kwc">$filename</span><span class="hl opt">,</span> <span class="hl kwc">$last_data</span><span class="hl opt">);</span>
<span class="hl kwc">$ret</span><span class="hl opt">[</span><span class="hl str">&quot;status&quot;</span><span class="hl opt">] =</span> <span class="hl str">&quot;success&quot;</span><span class="hl opt">;</span>

<span class="hl kwa">echo</span> <span class="hl kwd">json_encode</span><span class="hl opt">(</span><span class="hl kwc">$ret</span><span class="hl opt">);</span>
<span class="hl kwd">http_cache_etag</span><span class="hl opt">();</span>
<span class="hl kwd">http_send_content_type</span><span class="hl opt">(</span><span class="hl str">&quot;application/json&quot;</span><span class="hl opt">);</span>
<span class="hl kwd">http_send_data</span><span class="hl opt">(</span><span class="hl kwd">json_encode</span><span class="hl opt">(</span><span class="hl kwc">$ret</span><span class="hl opt">));</span>

<span class="hl slc">// Update statistics</span>
<span class="hl kwc">$redis</span><span class="hl opt">-&gt;</span><span class="hl kwd">incr</span><span class="hl opt">(</span><span class="hl str">&quot;stats:web:json:processed&quot;</span><span class="hl opt">);</span>
Expand Down

0 comments on commit e77b204

Please sign in to comment.