Permalink
Browse files

Writing test override to loader class for APC

  • Loading branch information...
1 parent 17732b2 commit 53c3d6a440aefa22d2cc8c26413d6911489007a5 @katzgrau committed Feb 21, 2011
Showing with 71 additions and 4 deletions.
  1. +2 −2 .gitignore
  2. +68 −0 application/core/MY_Output.php
  3. +1 −2 index.php
View
@@ -1,3 +1,3 @@
static/archives
-application/logs
-application/cache
+application/logs/*
+application/cache/*
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * An optimization to we can use APC instead of file-based page caching
+ */
+class MY_Output extends CI_Output
+{
+ /**
+ * An override to the core CodeIgniter page cache writing mechanism to use APC
+ * @param strint $output Page output
+ * @return void
+ */
+ function _write_cache($output)
+ {
+ if(!function_exists('apc_add'))
+ return parent::_write_cache ($output);
+
+ log_message('debug', 'Writing APC Cache');
+
+ $CI =& get_instance();
+
+ $uri = $CI->config->item('base_url').
+ $CI->config->item('index_page').
+ $CI->uri->uri_string();
+
+ $cache_key = md5($uri);
+
+ apc_store($cache_key, $output, $this->cache_expiration * 60);
+
+ return;
+ }
+
+ /**
+ * An override to the CI cache reading mechanism
+ * @param object $CFG CI config object
+ * @param object $URI CI uri object
+ * @return
+ */
+ function _display_cache(&$CFG, &$URI)
+ {
+ if(!function_exists('apc_add'))
+ return parent::_display_cache ($CFG, $URI);
+
+ log_message('debug', 'APC Cache Check');
+
+ $uri = $CFG->item('base_url').
+ $CFG->item('index_page').
+ $URI->uri_string;
+
+ $cache_key = md5($uri);
+
+ $output = apc_fetch($cache_key);
+
+ if($output === FALSE)
+ {
+ log_message('debug', 'APC Cache Miss..');
+ return FALSE;
+ }
+ else
+ {
+ log_message('debug', 'APC Cache Hit. Sending to browser.');
+ }
+
+ # Display the cached output
+ $this->_display($output);
+ return TRUE;
+ }
+}
View
@@ -1,5 +1,4 @@
<?php
-
/*
*---------------------------------------------------------------
* PHP ERROR REPORTING LEVEL
@@ -170,4 +169,4 @@
require_once BASEPATH.'core/CodeIgniter'.EXT;
/* End of file index.php */
-/* Location: ./index.php */
+/* Location: ./index.php */

0 comments on commit 53c3d6a

Please sign in to comment.