Complete modularization of the GC daemon

Summary: This modularizes the rest of the GC submethods. Turned out there was nothing tricky.

Test Plan: Ran `bin/phd debug garbage` and got reasonable looking behavior and output.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7971
This commit is contained in:
epriestley
2014-01-15 10:02:31 -08:00
parent 56d44f1503
commit 9f35c7cc26
11 changed files with 259 additions and 234 deletions

View File

@@ -0,0 +1,26 @@
<?php
final class PhabricatorCacheGeneralGarbageCollector
extends PhabricatorGarbageCollector {
public function collectGarbage() {
$key = 'gcdaemon.ttl.general-cache';
$ttl = PhabricatorEnv::getEnvConfig($key);
if ($ttl <= 0) {
return false;
}
$cache = new PhabricatorKeyValueDatabaseCache();
$conn_w = $cache->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE cacheCreated < %d
ORDER BY cacheCreated ASC LIMIT 100',
$cache->getTableName(),
time() - $ttl);
return ($conn_w->getAffectedRows() == 100);
}
}

View File

@@ -0,0 +1,25 @@
<?php
final class PhabricatorCacheMarkupGarbageCollector
extends PhabricatorGarbageCollector {
public function collectGarbage() {
$key = 'gcdaemon.ttl.markup-cache';
$ttl = PhabricatorEnv::getEnvConfig($key);
if ($ttl <= 0) {
return false;
}
$table = new PhabricatorMarkupCache();
$conn_w = $table->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
$table->getTableName(),
time() - $ttl);
return ($conn_w->getAffectedRows() == 100);
}
}

View File

@@ -0,0 +1,20 @@
<?php
final class PhabricatorCacheTTLGarbageCollector
extends PhabricatorGarbageCollector {
public function collectGarbage() {
$cache = new PhabricatorKeyValueDatabaseCache();
$conn_w = $cache->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE cacheExpires < %d
ORDER BY cacheExpires ASC LIMIT 100',
$cache->getTableName(),
time());
return ($conn_w->getAffectedRows() == 100);
}
}