From 3c3850dbaabf3efe313d35611dcc1959f0080b9b Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Mon, 18 Jul 2011 15:31:13 -0400
Subject: [PATCH] Issue #1051748: Load/store APC cache if available.

---
 drush     |    2 ++
 drush.php |   11 +++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/drush b/drush
index c3b59f3..b2d83be 100755
--- a/drush
+++ b/drush
@@ -41,6 +41,8 @@ if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != dumb ] && [ ! -z "`which tp
   fi
 fi
 
+export APC_PHP_CACHE='/dev/shm/drush.apc'
+
 if [ ! -z "$DRUSH_PHP" ] ; then
   # Use the DRUSH_PHP environment variable if it is available.
   php="$DRUSH_PHP"
diff --git a/drush.php b/drush.php
index 08be07d..f1f1606 100755
--- a/drush.php
+++ b/drush.php
@@ -8,6 +8,12 @@
  * @requires PHP CLI 5.2.0, or newer.
  */
 
+// Load the stored APC opcode cache, if available.
+define('DRUSH_APC_CACHE', getenv('DRUSH_APC_CACHE'));
+if (strlen(DRUSH_APC_CACHE) > 0 && function_exists('apc_bin_loadfile') && ini_get('apc.enable_cli') && is_readable(DRUSH_APC_CACHE)) {
+  apc_bin_loadfile(DRUSH_APC_CACHE);
+}
+
 require(dirname(__FILE__) . '/includes/bootstrap.inc');
 
 drush_bootstrap_prepare();
@@ -119,6 +125,11 @@ function drush_main() {
 
   drush_bootstrap_finish();
 
+  // Store the APC opcode cache.
+  if (defined('DRUSH_APC_CACHE') && function_exists('apc_bin_dumpfile') && ini_get('apc.enable_cli') && (is_writable(DRUSH_APC_CACHE) || is_writable(dirname(DRUSH_APC_CACHE)))) {
+    apc_bin_dumpfile(array(), NULL, DRUSH_APC_CACHE);
+  }
+
   // After this point the drush_shutdown function will run,
   // exiting with the correct exit code.
   return $return;
-- 
1.7.5.4

