1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 04:50:55 +01:00

Provide a pure APC cache for runtime caching

Summary:
Ref T11954. Depends on D16992. We have some data which can be generated and cached at runtime. Three examples are:

  - Class map from Conduit method names to implementing classes.
  - Class map from PHID types to implementing classes.
  - The main routing map.

None of these are huge wins but they impose global costs and can be shaved down through caching without introducing an enormous amount of new complexity.

The cost to these maps is that sometimes you'll need to restart your webserver, even in development mode if these caches are active. However, in some cases these changes are very rare, and in other cases we can just leave the cache disabled in development mode without a huge complexity cost.

Specifically, the Conduit/PHID type class maps are self-validating and can not go bad, even in development mode.

The routing map will be able to, but I plan to just disable it in development mode.

This provides a general-purpose pure APC cache stack for storing this data.

Test Plan: See future changes.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11954

Differential Revision: https://secure.phabricator.com/D16993
This commit is contained in:
epriestley 2016-12-06 03:30:06 -08:00
parent 4faa4b451f
commit 52112620a3

View file

@ -117,6 +117,42 @@ final class PhabricatorCaches extends Phobject {
}
/* -( Runtime Cache )------------------------------------------------------ */
/**
* Get a runtime cache stack.
*
* This stack is just APC. It's fast, it's effectively immutable, and it
* gets thrown away when the webserver restarts.
*
* This cache is suitable for deriving runtime caches, like a map of Conduit
* method names to provider classes.
*
* @return PhutilKeyValueCacheStack Best runtime stack available.
*/
public static function getRuntimeCache() {
static $cache;
if (!$cache) {
$caches = self::buildRuntimeCaches();
$cache = self::newStackFromCaches($caches);
}
return $cache;
}
private static function buildRuntimeCaches() {
$caches = array();
$apc = new PhutilAPCKeyValueCache();
if ($apc->isAvailable()) {
$caches[] = $apc;
}
return $caches;
}
/* -( Repository Graph Cache )--------------------------------------------- */