Page MenuHomePhabricator

D13153.diff
No OneTemporary

D13153.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1495,6 +1495,7 @@
'PhabricatorCacheSpec' => 'applications/cache/spec/PhabricatorCacheSpec.php',
'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php',
'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php',
+ 'PhabricatorCachesTestCase' => 'applications/cache/__tests__/PhabricatorCachesTestCase.php',
'PhabricatorCalendarApplication' => 'applications/calendar/application/PhabricatorCalendarApplication.php',
'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php',
'PhabricatorCalendarDAO' => 'applications/calendar/storage/PhabricatorCalendarDAO.php',
@@ -4852,6 +4853,7 @@
'PhabricatorCacheSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorCacheSpec' => 'Phobject',
'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector',
+ 'PhabricatorCachesTestCase' => 'PhabricatorTestCase',
'PhabricatorCalendarApplication' => 'PhabricatorApplication',
'PhabricatorCalendarController' => 'PhabricatorController',
'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO',
diff --git a/src/applications/cache/PhabricatorCaches.php b/src/applications/cache/PhabricatorCaches.php
--- a/src/applications/cache/PhabricatorCaches.php
+++ b/src/applications/cache/PhabricatorCaches.php
@@ -1,12 +1,16 @@
<?php
/**
+ *
+ * @task request Request Cache
* @task immutable Immutable Cache
* @task setup Setup Cache
* @task compress Compression
*/
final class PhabricatorCaches {
+ private static $requestCache;
+
public static function getNamespace() {
return PhabricatorEnv::getEnvConfig('phabricator.cache-namespace');
}
@@ -18,8 +22,39 @@
->setCaches($caches);
}
+/* -( Request Cache )------------------------------------------------------ */
+
+
+ /**
+ * Get a request cache stack.
+ *
+ * This cache stack is destroyed after each logical request. In particular,
+ * it is destroyed periodically by the daemons, while `static` caches are
+ * not.
+ *
+ * @return PhutilKeyValueCacheStack Request cache stack.
+ */
+ public static function getRequestCache() {
+ if (!self::$requestCache) {
+ self::$requestCache = new PhutilInRequestKeyValueCache();
+ }
+ return self::$requestCache;
+ }
+
+
+ /**
+ * Destroy the request cache.
+ *
+ * This is called at the beginning of each logical request.
+ *
+ * @return void
+ */
+ public static function destroyRequestCache() {
+ self::$requestCache = null;
+ }
+
-/* -( Local Cache )-------------------------------------------------------- */
+/* -( Immutable Cache )---------------------------------------------------- */
/**
diff --git a/src/applications/cache/__tests__/PhabricatorCachesTestCase.php b/src/applications/cache/__tests__/PhabricatorCachesTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/applications/cache/__tests__/PhabricatorCachesTestCase.php
@@ -0,0 +1,41 @@
+<?php
+
+final class PhabricatorCachesTestCase
+ extends PhabricatorTestCase {
+
+ public function testRequestCache() {
+ $cache = PhabricatorCaches::getRequestCache();
+
+ $test_key = 'unit.'.Filesystem::readRandomCharacters(8);
+
+ $default_value = pht('Default');
+ $new_value = pht('New Value');
+
+ $this->assertEqual(
+ $default_value,
+ $cache->getKey($test_key, $default_value));
+
+ // Set a key, verify it persists.
+ $cache = PhabricatorCaches::getRequestCache();
+ $cache->setKey($test_key, $new_value);
+ $this->assertEqual(
+ $new_value,
+ $cache->getKey($test_key, $default_value));
+
+ // Refetch the cache, verify it's really a cache.
+ $cache = PhabricatorCaches::getRequestCache();
+ $this->assertEqual(
+ $new_value,
+ $cache->getKey($test_key, $default_value));
+
+ // Destroy the cache.
+ PhabricatorCaches::destroyRequestCache();
+
+ // Now, the value should be missing again.
+ $cache = PhabricatorCaches::getRequestCache();
+ $this->assertEqual(
+ $default_value,
+ $cache->getKey($test_key, $default_value));
+ }
+
+}
diff --git a/src/applications/fact/daemon/PhabricatorFactDaemon.php b/src/applications/fact/daemon/PhabricatorFactDaemon.php
--- a/src/applications/fact/daemon/PhabricatorFactDaemon.php
+++ b/src/applications/fact/daemon/PhabricatorFactDaemon.php
@@ -9,6 +9,8 @@
protected function run() {
$this->setEngines(PhabricatorFactEngine::loadAllEngines());
while (!$this->shouldExit()) {
+ PhabricatorCaches::destroyRequestCache();
+
$iterators = $this->getAllApplicationIterators();
foreach ($iterators as $iterator_name => $iterator) {
$this->processIteratorWithCursor($iterator_name, $iterator);
diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
--- a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
+++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
@@ -73,6 +73,7 @@
$queue = array();
while (!$this->shouldExit()) {
+ PhabricatorCaches::destroyRequestCache();
$pullable = $this->loadPullableRepositories($include, $exclude);
// If any repositories have the NEEDS_UPDATE flag set, pull them
diff --git a/src/infrastructure/daemon/bot/PhabricatorBot.php b/src/infrastructure/daemon/bot/PhabricatorBot.php
--- a/src/infrastructure/daemon/bot/PhabricatorBot.php
+++ b/src/infrastructure/daemon/bot/PhabricatorBot.php
@@ -106,6 +106,8 @@
private function runLoop() {
do {
+ PhabricatorCaches::destroyRequestCache();
+
$this->stillWorking();
$messages = $this->protocolAdapter->getNextMessages($this->pollFrequency);
diff --git a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
--- a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
+++ b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
@@ -4,6 +4,8 @@
protected function run() {
do {
+ PhabricatorCaches::destroyRequestCache();
+
$tasks = id(new PhabricatorWorkerLeaseQuery())
->setLimit(1)
->execute();
diff --git a/src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php b/src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php
--- a/src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php
+++ b/src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php
@@ -65,6 +65,8 @@
$this->nextCollection = PhabricatorTime::getNow();
do {
+ PhabricatorCaches::destroyRequestCache();
+
$lock = PhabricatorGlobalLock::newLock('trigger');
try {
diff --git a/webroot/index.php b/webroot/index.php
--- a/webroot/index.php
+++ b/webroot/index.php
@@ -13,6 +13,8 @@
try {
PhabricatorStartup::loadCoreLibraries();
+ PhabricatorCaches::destroyRequestCache();
+
$sink = new AphrontPHPHTTPSink();
try {

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 1:16 AM (17 h, 14 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6775403
Default Alt Text
D13153.diff (7 KB)

Event Timeline