[FEATURE] Added Ajax JSON Memcache

This commit is contained in:
Sebastian Grewe 2013-09-18 13:11:24 +02:00
parent f41ea296df
commit bd8796b824
3 changed files with 25 additions and 1 deletions

View File

@ -30,13 +30,19 @@ class Api extends Base {
* @return string JSON object
**/
function get_json($data, $force=false) {
return json_encode(
// Create a request specific memcache key
$sMemcacheKey = @$_REQUEST['page'] . '_' . @$_REQUEST['action'] . '_' . __FUNCTION__ . '_' . @$SESSION['USERDATA']['id'] . '_' . $_SESSION['REMOTE_ADDR'];
if ($this->setting->getValue('statistics_ajax_cache') && $json_data = $this->memcache->get($sMemcacheKey)) return $json_data;
$json_data =json_encode(
array( $_REQUEST['action'] => array(
'version' => $this->api_version,
'runtime' => (microtime(true) - $this->dStartTime) * 1000,
'data' => $data
)), $force ? JSON_FORCE_OBJECT : 0
);
if (! $expiration = $this->setting->getValue('statistics_ajax_cache_expiration')) $expiration = 10;
if ($this->setting->getValue('statistics_ajax_cache'))
return $this->memcache->setCache($sMemcacheKey, $json_data, $expiration);
}
/**
@ -63,4 +69,5 @@ $api = new Api();
$api->setConfig($config);
$api->setUser($user);
$api->setSetting($setting);
$api->setMemcache($memcache);
$api->setStartTime($dStartTime);

View File

@ -37,6 +37,9 @@ class Base {
public function setSetting($setting) {
$this->setting = $setting;
}
public function setMemcache($memcache) {
$this->memcache = $memcache;
}
public function setBitcoin($bitcoin) {
$this->bitcoin = $bitcoin;
}

View File

@ -116,6 +116,20 @@ $aSettings['statistics'][] = array(
'name' => 'statistics_ajax_data_interval', 'value' => $setting->getValue('statistics_ajax_data_interval'),
'tooltip' => 'Time in minutes, interval for hashrate and sharerate calculations. Higher intervals allow for better accuracy at a higer server load.'
);
$aSettings['statistics'][] = array(
'display' => 'Ajax Caching', 'type' => 'select',
'options' => array('0' => 'No', '1' => 'Yes'),
'default' => 0,
'name' => 'statistics_ajax_cache', 'value' => $setting->getValue('statistics_ajax_cache'),
'tooltip' => 'Enable or disable the Ajax cache for memcache.'
);
$aSettings['statistics'][] = array(
'display' => 'Ajax Cache Expiration', 'type' => 'select',
'options' => array('5' => '5', '10' => '10', '20' => '20', '40' => '40', '60' => '60'),
'default' => 10,
'name' => 'statistics_ajax_cache_expiration', 'value' => $setting->getValue('statistics_ajax_cache_expiration'),
'tooltip' => 'Change expiration time for memcache keys.'
);
$aSettings['statistics'][] = array(
'display' => 'Block Statistics Count', 'type' => 'text',
'size' => 25,