[ADDED] Static cache with no auto-expiration
This commit is contained in:
parent
3cb546cea5
commit
8ef419f795
@ -487,7 +487,7 @@ class Statistics extends Base {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$aData['data'][$row['id']] = $row;
|
||||
}
|
||||
return $this->memcache->setCache(STATISTICS_ALL_USER_HASHRATES, $aData);
|
||||
return $this->memcache->setStaticCache(STATISTICS_ALL_USER_HASHRATES, $aData, 600);
|
||||
} else {
|
||||
return $this->sqlError();
|
||||
}
|
||||
@ -501,7 +501,7 @@ class Statistics extends Base {
|
||||
public function getUserHashrate($account_id, $interval=180) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||
if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if (array_key_exists($account_id, $data['data']))
|
||||
return $data['data'][$account_id]['hashrate'];
|
||||
// We have no cached value, we return defaults
|
||||
@ -563,7 +563,7 @@ class Statistics extends Base {
|
||||
public function getUserShareDifficulty($account_id, $interval=180) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||
if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if (array_key_exists($account_id, $data['data']))
|
||||
return $data['data'][$account_id]['avgsharediff'];
|
||||
// We have no cached value, we return defaults
|
||||
@ -592,7 +592,7 @@ class Statistics extends Base {
|
||||
public function getUserSharerate($account_id, $interval=180) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
// Dual-caching, try statistics cron first, then fallback to local, then fallbock to SQL
|
||||
if ($data = $this->memcache->get(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if ($data = $this->memcache->getStatic(STATISTICS_ALL_USER_HASHRATES)) {
|
||||
if (array_key_exists($account_id, $data['data']))
|
||||
return $data['data'][$account_id]['sharerate'];
|
||||
// We have no cached value, we return defaults
|
||||
|
||||
@ -44,6 +44,18 @@ class StatsCache {
|
||||
return $this->cache->set($this->getRound() . '_' . $this->config['memcache']['keyprefix'] . $key, $value, $expiration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special memcache->set call bypassing any auto-expiration systems
|
||||
* Can be used as a static, auto-updated cache via crons
|
||||
**/
|
||||
public function setStaticCache($key, $value, $expiration=NULL) {
|
||||
if (! $this->config['memcache']['enabled']) return false;
|
||||
if (empty($expiration))
|
||||
$expiration = $this->config['memcache']['expiration'] + rand( -$this->config['memcache']['splay'], $this->config['memcache']['splay']);
|
||||
$this->debug->append("Storing " . $this->config['memcache']['keyprefix'] . "$key with expiration $expiration", 3);
|
||||
return $this->cache->set($this->config['memcache']['keyprefix'] . $key, $value, $expiration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around memcache->get
|
||||
* Always return false if memcache is disabled
|
||||
@ -58,6 +70,21 @@ class StatsCache {
|
||||
$this->debug->append("Key not found", 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As the static set call, we try to fetch static data here
|
||||
**/
|
||||
public function getStatic($key, $cache_cb = NULL, &$cas_token = NULL) {
|
||||
if (! $this->config['memcache']['enabled']) return false;
|
||||
$this->debug->append("Trying to fetch key " . $this->config['memcache']['keyprefix'] . "$key from cache", 3);
|
||||
if ($data = $this->cache->get($this->config['memcache']['keyprefix'].$key)) {
|
||||
$this->debug->append("Found key in cache", 3);
|
||||
return $data;
|
||||
} else {
|
||||
$this->debug->append("Key not found", 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Another wrapper, we want to store data in memcache and return the actual data
|
||||
* for further processing
|
||||
|
||||
Loading…
Reference in New Issue
Block a user