add cache only

This commit is contained in:
Niko Storni 2018-12-03 19:47:00 -05:00
parent 3eab838967
commit 3884c74e7d
3 changed files with 341 additions and 565 deletions

View file

@ -6,14 +6,14 @@
"license": "MIT",
"require": {
"php": ">=5.6",
"cakephp/cakephp": "^3.6",
"cakephp/cakephp": "3.4.*",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "~1.0",
"mdanter/ecc": "^0.5.0",
"nesbot/carbon": "~1.18",
"endroid/qrcode": "^2.2.2",
"predis/predis": "^1.1.1"
"predis/predis": "^1.1.1",
"endroid/qr-code": "^3.5"
},
"require-dev": {
"psy/psysh": "@stable",

846
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,8 @@ class MainController extends AppController {
const lbcPriceKey = 'lbc.price';
const txOutSetInfo = 'lbrcrd.tosi';
const bittrexMarketUrl = 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LBC';
const blockchainTickerUrl = 'https://blockchain.info/ticker';
@ -697,17 +699,47 @@ class MainController extends AppController {
}
}
private function _gettxoutsetinfo() {
$req = ['method' => 'gettxoutsetinfo', 'params' => []];
try {
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
if (!isset($res->result)) {
return 0;
protected function _gettxoutsetinfo() {
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$txOutSetInfo = new \stdClass();
$txOutSetInfo->time = $now->format('c');
$shouldRefreshSet = false;
if (!$this->redis) {
$shouldRefreshSet = true;
} else {
if (!$this->redis->exists(self::txOutSetInfo)) {
$shouldRefreshSet = true;
} else {
$txOutSetInfo = json_decode($this->redis->get(self::txOutSetInfo));
$lastTOSIDt = new \DateTime($txOutSetInfo->time);
$diff = $now->diff($lastTOSIDt);
$diffMinutes = $diff->i;
if ($diffMinutes >= 15 || $txOutSetInfo->set == 'N/A') {
$shouldRefreshSet = true;
}
}
return $res->result;
} catch (\Exception $e) {
return 'N/A';
}
if ($shouldRefreshSet) {
$req = ['method' => 'gettxoutsetinfo', 'params' => []];
try {
$res = json_decode(self::curl_json_post(self::$rpcurl, json_encode($req)));
if (!isset($res->result)) {
$txOutSetInfo->tosi = 'N/A';
}
$txOutSetInfo->tosi = $res->result;
} catch (\Exception $e) {
$txOutSetInfo->tosi = 'N/A';
}
$txOutSetInfo->time = $now->format('c');
if ($this->redis) {
$this->redis->set(self::txOutSetInfo, json_encode($txOutSetInfo));
}
}
return (isset($txOutSetInfo->tosi)) ? $txOutSetInfo->tosi : 'N/A';
}
public function apistatus() {
@ -936,6 +968,4 @@ class MainController extends AppController {
// Close any open file handle
return $response;
}
}
?>
}