public static function getLiveServers() { $cache = PhabricatorCaches::getRequestCache(); $refs = $cache->getKey(self::KEY_REFS); if (!$refs) { $refs = self::newRefs(); $cache->setKey(self::KEY_REFS, $refs); } return $refs; }
private function getEngine() { $options = $this->options; $viewer = $this->getViewer(); $viewer_key = $viewer->getCacheFragment(); ksort($options); $engine_key = serialize($options); $engine_key = PhabricatorHash::digestForIndex($engine_key); $cache = PhabricatorCaches::getRequestCache(); $cache_key = "remarkup.engine({$viewer_key}, {$engine_key})"; $engine = $cache->getKey($cache_key); if (!$engine) { $engine = PhabricatorMarkupEngine::newMarkupEngine($options); $cache->setKey($cache_key, $engine); } return $engine; }
public static function getLiveDevice() { $device_id = self::getDeviceID(); if (!$device_id) { return null; } $cache = PhabricatorCaches::getRequestCache(); $cache_key = 'almanac.device.self'; $device = $cache->getKey($cache_key); if (!$device) { $viewer = PhabricatorUser::getOmnipotentUser(); $device = id(new AlmanacDeviceQuery())->setViewer($viewer)->withNames(array($device_id))->executeOne(); if (!$device) { throw new Exception(pht('This host has device ID "%s", but there is no corresponding ' . 'device record in Almanac.', $device_id)); } $cache->setKey($cache_key, $device); } return $device; }
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)); }
/** * Determine if an application is installed and available to a viewer, by * application class name. * * To check if an application is installed at all, use * @{method:isClassInstalled}. * * @param string Application class name. * @param PhabricatorUser Viewing user. * @return bool True if the class is installed for the viewer. * @task meta */ public static final function isClassInstalledForViewer($class, PhabricatorUser $viewer) { if ($viewer->isOmnipotent()) { return true; } $cache = PhabricatorCaches::getRequestCache(); $viewer_phid = $viewer->getPHID(); $key = 'app.' . $class . '.installed.' . $viewer_phid; $result = $cache->getKey($key); if ($result === null) { if (!self::isClassInstalled($class)) { $result = false; } else { $result = PhabricatorPolicyFilter::hasCapability($viewer, self::getByClass($class), PhabricatorPolicyCapability::CAN_VIEW); } $cache->setKey($key, $result); } return $result; }
/** * @task order */ public function getOrderableColumns() { $cache = PhabricatorCaches::getRequestCache(); $class = get_class($this); $cache_key = 'query.orderablecolumns.' . $class; $columns = $cache->getKey($cache_key); if ($columns !== null) { return $columns; } $columns = array('id' => array('table' => $this->getPrimaryTableAlias(), 'column' => 'id', 'reverse' => false, 'type' => 'int', 'unique' => true)); $object = $this->newResultObject(); if ($object instanceof PhabricatorCustomFieldInterface) { $list = PhabricatorCustomField::getObjectFields($object, PhabricatorCustomField::ROLE_APPLICATIONSEARCH); foreach ($list->getFields() as $field) { $index = $field->buildOrderIndex(); if (!$index) { continue; } $digest = $field->getFieldIndex(); $key = $field->getModernFieldKey(); $columns[$key] = array('table' => 'appsearch_order_' . $digest, 'column' => 'indexValue', 'type' => $index->getIndexValueType(), 'null' => 'tail', 'customfield' => true, 'customfield.index.table' => $index->getTableName(), 'customfield.index.key' => $digest); } } $cache->setKey($cache_key, $columns); return $columns; }
public static function getLiveIndividualRef() { $cache = PhabricatorCaches::getRequestCache(); $ref = $cache->getKey(self::KEY_INDIVIDUAL); if (!$ref) { $ref = self::newIndividualRef(); $cache->setKey(self::KEY_INDIVIDUAL, $ref); } return $ref; }
protected final function getTransactionHint(PhabricatorPolicyInterface $object) { $cache = PhabricatorCaches::getRequestCache(); return $cache->getKey(self::getObjectPolicyCacheKey($object, $this)); }
public static function getViewerSpaces(PhabricatorUser $viewer) { $cache = PhabricatorCaches::getRequestCache(); $cache_key = self::KEY_VIEWER . '(' . $viewer->getPHID() . ')'; $result = $cache->getKey($cache_key); if ($result === null) { $spaces = self::getAllSpaces(); $result = array(); foreach ($spaces as $key => $space) { $can_see = PhabricatorPolicyFilter::hasCapability($viewer, $space, PhabricatorPolicyCapability::CAN_VIEW); if ($can_see) { $result[$key] = $space; } } $cache->setKey($cache_key, $result); } return $result; }