Implemented DB Caching
This commit is contained in:
parent
a2bd137386
commit
525e77203d
|
@ -11,12 +11,13 @@ return array(
|
|||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
'dbdriver' => 'mysqli',
|
||||
'dbdriver' => '',
|
||||
'subdriver'=> '',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'cachedir' => '',
|
||||
'cachedir' => 'Application/Cache',
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
|
@ -24,7 +25,6 @@ return array(
|
|||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
'save_queries' => TRUE
|
||||
),
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
use FuzeWorks\Logger;
|
||||
use Fuzeworks\Factory;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* Database Cache Class
|
||||
|
@ -43,17 +44,9 @@ use Fuzeworks\Factory;
|
|||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @todo Fix URI
|
||||
*/
|
||||
class FW_DB_Cache {
|
||||
|
||||
/**
|
||||
* CI Singleton
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $CI;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
|
@ -81,7 +74,7 @@ class FW_DB_Cache {
|
|||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
// Assign the main CI object to $this->CI and load the file helper since we use it a lot
|
||||
$this->db =& $db;
|
||||
$this->factory = Factory::getInstance();
|
||||
$this->factory->helpers->load('file');
|
||||
|
||||
|
@ -121,7 +114,7 @@ class FW_DB_Cache {
|
|||
return $this->db->cache_off();
|
||||
}
|
||||
|
||||
if ( ! is_really_writable($path))
|
||||
if ( ! Core::isReallyWritable($path))
|
||||
{
|
||||
Logger::logDebug('DB cache dir not writable: '.$path);
|
||||
|
||||
|
@ -146,8 +139,8 @@ class FW_DB_Cache {
|
|||
*/
|
||||
public function read($sql)
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
|
||||
|
||||
if (FALSE === ($cachedata = @file_get_contents($filepath)))
|
||||
|
@ -169,8 +162,8 @@ class FW_DB_Cache {
|
|||
*/
|
||||
public function write($sql, $object)
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
$filename = md5($sql);
|
||||
|
||||
|
@ -201,12 +194,12 @@ class FW_DB_Cache {
|
|||
{
|
||||
if ($segment_one === '')
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
}
|
||||
|
||||
if ($segment_two === '')
|
||||
{
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
}
|
||||
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
* @version Version 0.0.1
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\DatabaseException;
|
||||
use FuzeWorks\Utf8;
|
||||
|
@ -375,7 +376,7 @@ abstract class FW_DB_driver {
|
|||
|
||||
$this->factory = Factory::getInstance();
|
||||
|
||||
Logger::log('Database Driver Class Initialized');
|
||||
Logger::log('Database Driver ' . get_class($this) . ' Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -1739,14 +1740,13 @@ abstract class FW_DB_driver {
|
|||
* @param string any "swap" values
|
||||
* @param bool whether to localize the message
|
||||
* @return string sends the application/views/errors/error_db.php template
|
||||
* @todo FIX THIS
|
||||
*/
|
||||
public function display_error($error = '', $swap = '', $native = FALSE)
|
||||
{
|
||||
// First load the language
|
||||
$LANG = Language::get('db');
|
||||
Language::get('db');
|
||||
|
||||
$heading = $LANG->line('db_error_heading');
|
||||
$heading = Language::line('db_error_heading');
|
||||
|
||||
if ($native === TRUE)
|
||||
{
|
||||
|
@ -1754,7 +1754,7 @@ abstract class FW_DB_driver {
|
|||
}
|
||||
else
|
||||
{
|
||||
$message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error)));
|
||||
$message = is_array($error) ? $error : array(str_replace('%s', $swap, Language::line($error)));
|
||||
}
|
||||
|
||||
// Find the most likely culprit of the error by going through
|
||||
|
@ -1774,14 +1774,17 @@ abstract class FW_DB_driver {
|
|||
if (strpos($call['file'], 'Core'.DS.'Database') === FALSE && strpos($call['class'], 'Loader') === FALSE)
|
||||
{
|
||||
// Found it - use a relative path for safety
|
||||
$message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']);
|
||||
$message[] = 'Filename: '.str_replace(array('Application', 'Core'), '', $call['file']);
|
||||
$message[] = 'Line Number: '.$call['line'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::logError($heading . ' || ' . $message);
|
||||
Logger::logError($heading);
|
||||
foreach ($message as $message) {
|
||||
Logger::logError($message);
|
||||
}
|
||||
Logger::http_error(500);
|
||||
exit(8); // EXIT_DATABASE
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue