cleanup of PurgeLimiter #342
This commit is contained in:
parent
3470dcd9a8
commit
4a35428499
@ -70,23 +70,18 @@ class PurgeLimiter extends AbstractPersistence
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = 'purge_limiter.php';
|
|
||||||
$now = time();
|
$now = time();
|
||||||
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';' . PHP_EOL;
|
$file = 'purge_limiter.php';
|
||||||
if (!self::_exists($file)) {
|
if (self::_exists($file)) {
|
||||||
self::_store($file, $content);
|
require self::getPath($file);
|
||||||
}
|
|
||||||
|
|
||||||
$path = self::getPath($file);
|
|
||||||
require $path;
|
|
||||||
$pl = $GLOBALS['purge_limiter'];
|
$pl = $GLOBALS['purge_limiter'];
|
||||||
|
|
||||||
if ($pl + self::$_limit >= $now) {
|
if ($pl + self::$_limit >= $now) {
|
||||||
$result = false;
|
return false;
|
||||||
} else {
|
}
|
||||||
$result = true;
|
}
|
||||||
|
|
||||||
|
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';';
|
||||||
self::_store($file, $content);
|
self::_store($file, $content);
|
||||||
}
|
return true;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ class PurgeLimiterTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testLimit()
|
public function testLimit()
|
||||||
{
|
{
|
||||||
// initialize it
|
// initialize it
|
||||||
|
PurgeLimiter::setLimit(1);
|
||||||
PurgeLimiter::canPurge();
|
PurgeLimiter::canPurge();
|
||||||
|
|
||||||
// try setting it
|
// try setting it
|
||||||
PurgeLimiter::setLimit(1);
|
|
||||||
$this->assertEquals(false, PurgeLimiter::canPurge());
|
$this->assertEquals(false, PurgeLimiter::canPurge());
|
||||||
sleep(2);
|
sleep(2);
|
||||||
$this->assertEquals(true, PurgeLimiter::canPurge());
|
$this->assertEquals(true, PurgeLimiter::canPurge());
|
||||||
|
Loading…
Reference in New Issue
Block a user