Skip to content

Commit

Permalink
Web: Prefer to always use cached news/dev feed content
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 9, 2017
1 parent 28d63c6 commit 9cd004d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions webapi/1/include/cache.inc.php
Expand Up @@ -52,12 +52,12 @@ function cache_key($id, $data)
return "/$id/".urlencode(json_encode($data));
}

function cache_try_load($key)
function cache_try_load($key, $max_age = DENG_CACHE_MAX_AGE)
{
$fn = DENG_CACHE_PATH.$key;
if (!file_exists($fn)) return false;
$ts = filemtime($fn);
if (time() - $ts > DENG_CACHE_MAX_AGE) return false; // Too old.
if ($max_age >= 0 && (time() - $ts) > $max_age) return false; // Too old.
if (($value = file_get_contents($fn)) === false) return false;
global $_cache_buf;
global $_cache_ts;
Expand Down
6 changes: 3 additions & 3 deletions webapi/1/news.php
Expand Up @@ -23,13 +23,13 @@ function fetch_blog_feed($category)
header("Cache-Control: max-age=900");
header('Content-Type: application/json');

$json_url = "http://dengine.net/blog/category/$category/?json=true&count=3";
$ckey = cache_key('news', $category);
if (cache_try_load($ckey)) {
if (cache_try_load($ckey, -1)) { // always use the cached data
cache_dump();
return;
}


$json_url = "http://dengine.net/blog/category/$category/?json=true&count=3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // as a string
Expand Down

0 comments on commit 9cd004d

Please sign in to comment.