Skip to content

Commit

Permalink
More efficient way of checking for GC trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 3, 2014
1 parent 2dda3c7 commit 55e5ca3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion framework/Cache/lib/Horde/Cache/Storage/Mongo.php
Expand Up @@ -59,7 +59,7 @@ public function __construct(array $params = array())
public function __destruct()
{
/* Only do garbage collection 0.1% of the time we create an object. */
if (rand(0, 999) == 0) {
if (substr(time(), -3) === '000') {
try {
$this->_db->remove(array(
self::EXPIRE => array(
Expand Down
2 changes: 1 addition & 1 deletion framework/Cache/lib/Horde/Cache/Storage/Sql.php
Expand Up @@ -77,7 +77,7 @@ protected function _initOb()
public function __destruct()
{
/* Only do garbage collection 0.1% of the time we create an object. */
if (rand(0, 999) != 0) {
if (substr(time(), -3) !== '000') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion framework/Lock/lib/Horde/Lock/Sql.php
Expand Up @@ -65,7 +65,7 @@ public function __construct($params = array())

/* Only do garbage collection if asked for, and then only 0.1% of the
* time we create an object. */
if (rand(0, 999) == 0) {
if (substr(time(), -3) === '000') {
register_shutdown_function(array($this, 'doGC'));
}
}
Expand Down
Expand Up @@ -73,7 +73,8 @@ public function __construct(array $params = array())
$this->_params['track_lifetime'] = ini_get('session.gc_maxlifetime');
}

if (!empty($this->_params['track']) && (rand(0, 999) == 0)) {
if (!empty($this->_params['track']) &&
(substr(time(), -3) === '000')) {
register_shutdown_function(array($this, 'trackGC'));
}
}
Expand Down

0 comments on commit 55e5ca3

Please sign in to comment.