From 52112620a3d2e8bac28c7f65ac62e576ac8ad47b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Dec 2016 03:30:06 -0800 Subject: [PATCH] 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 --- src/applications/cache/PhabricatorCaches.php | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/applications/cache/PhabricatorCaches.php b/src/applications/cache/PhabricatorCaches.php index a725238150..1add0685c2 100644 --- a/src/applications/cache/PhabricatorCaches.php +++ b/src/applications/cache/PhabricatorCaches.php @@ -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 )--------------------------------------------- */