Skip to content

Commit

Permalink
Basic caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ripexz committed Aug 25, 2014
1 parent a64f901 commit fdc4e4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions php/get_d2l_data.php → php/get_data.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

//check for this message and stop work if servers are overloaded
$errMsg = "Servers are under very heavy load or item draft is under progress.";
$nfMsg = "Looks like there's no site that you´re looking for.";
Expand Down Expand Up @@ -122,6 +125,11 @@
}
}

if ($next != $last || mysqli_num_rows($result2) > 0) {
// Invalidate cache:
$memcached->delete("dota2_match_data");
}

function file_get_contents_curl($url, $timeout = 0) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
Expand Down
12 changes: 12 additions & 0 deletions php/get_json.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

header('Content-Type: application/json');

$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

$mdata = $memcached->get("dota2_match_data");
if ($mdata) {
echo $mdata;
exit();
}

$db = mysqli_connect( 'localhost', 'username', 'password', 'dbname' );
if ( !$db ) {
die();
Expand All @@ -24,6 +35,7 @@
}

$json .= "]}";
$memcached->set("dota2_match_data", $json);
echo $json;

?>

0 comments on commit fdc4e4e

Please sign in to comment.