// MCached renamed in CacheMemcache + CacheFS renamed in CacheFs
This commit is contained in:
@@ -42,19 +42,19 @@ class AdminPerformance extends AdminTab
|
|||||||
$this->_errors[] = Tools::displayError('Caching system is missing');
|
$this->_errors[] = Tools::displayError('Caching system is missing');
|
||||||
else
|
else
|
||||||
$settings = preg_replace('/define\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\/+-_]+)\'\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \''.$caching_system.'\');', $settings);
|
$settings = preg_replace('/define\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\/+-_]+)\'\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \''.$caching_system.'\');', $settings);
|
||||||
if ($cache_active AND $caching_system == 'MCached' AND !extension_loaded('memcache'))
|
if ($cache_active AND $caching_system == 'CacheMemcache' AND !extension_loaded('memcache'))
|
||||||
$this->_errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.').' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
|
$this->_errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.').' <a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
|
||||||
elseif ($cache_active AND $caching_system == 'CacheFS' AND !is_writable(_PS_CACHEFS_DIRECTORY_))
|
elseif ($cache_active AND $caching_system == 'CacheFs' AND !is_writable(_PS_CACHEFS_DIRECTORY_))
|
||||||
$this->_errors[] = Tools::displayError('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.Tools::displayError('must be writable');
|
$this->_errors[] = Tools::displayError('To use CacheFS the directory').' '.realpath(_PS_CACHEFS_DIRECTORY_).' '.Tools::displayError('must be writable');
|
||||||
|
|
||||||
if ($caching_system == 'CacheFS')
|
if ($caching_system == 'CacheFs')
|
||||||
{
|
{
|
||||||
if (!($depth = Tools::getValue('ps_cache_fs_directory_depth')))
|
if (!($depth = Tools::getValue('ps_cache_fs_directory_depth')))
|
||||||
$this->_errors[] = Tools::displayError('Please set a directory depth');
|
$this->_errors[] = Tools::displayError('Please set a directory depth');
|
||||||
if (!sizeof($this->_errors))
|
if (!sizeof($this->_errors))
|
||||||
{
|
{
|
||||||
CacheFS::deleteCacheDirectory();
|
CacheFs::deleteCacheDirectory();
|
||||||
CacheFS::createCacheDirectories((int)$depth);
|
CacheFs::createCacheDirectories((int)$depth);
|
||||||
Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int)$depth);
|
Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int)$depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ class AdminPerformance extends AdminTab
|
|||||||
$this->_errors[] = Tools::displayError('Memcached weight is missing');
|
$this->_errors[] = Tools::displayError('Memcached weight is missing');
|
||||||
if (!sizeof($this->_errors))
|
if (!sizeof($this->_errors))
|
||||||
{
|
{
|
||||||
if (MCached::addServer(pSQL(Tools::getValue('memcachedIp')), (int)Tools::getValue('memcachedPort'), (int)Tools::getValue('memcachedWeight')))
|
if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int)Tools::getValue('memcachedPort'), (int)Tools::getValue('memcachedWeight')))
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
|
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('Cannot add Memcached server');
|
$this->_errors[] = Tools::displayError('Cannot add Memcached server');
|
||||||
@@ -95,7 +95,7 @@ class AdminPerformance extends AdminTab
|
|||||||
{
|
{
|
||||||
if ($this->tabAccess['add'] === '1')
|
if ($this->tabAccess['add'] === '1')
|
||||||
{
|
{
|
||||||
if (MCached::deleteServer((int)Tools::getValue('deleteMemcachedServer')))
|
if (CacheMemcache::deleteServer((int)Tools::getValue('deleteMemcachedServer')))
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
|
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('Error in deleting Memcached server');
|
$this->_errors[] = Tools::displayError('Error in deleting Memcached server');
|
||||||
@@ -441,8 +441,8 @@ class AdminPerformance extends AdminTab
|
|||||||
<label>'.$this->l('Caching system:').' </label>
|
<label>'.$this->l('Caching system:').' </label>
|
||||||
<div class="margin-form">
|
<div class="margin-form">
|
||||||
<select name="caching_system" id="caching_system">
|
<select name="caching_system" id="caching_system">
|
||||||
<option value="MCached" '.(_PS_CACHING_SYSTEM_ == 'MCached' ? 'selected="selected"' : '' ).'>'.$this->l('Memcached').'</option>
|
<option value="CacheMemcache" '.(_PS_CACHING_SYSTEM_ == 'CacheMemcache' ? 'selected="selected"' : '' ).'>'.$this->l('Memcached').'</option>
|
||||||
<option value="CacheFS" '.(_PS_CACHING_SYSTEM_ == 'CacheFS' ? 'selected="selected"' : '' ).'>'.$this->l('File System').'</option>
|
<option value="CacheFs" '.(_PS_CACHING_SYSTEM_ == 'CacheFs' ? 'selected="selected"' : '' ).'>'.$this->l('File System').'</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="directory_depth">
|
<div id="directory_depth">
|
||||||
@@ -479,7 +479,7 @@ class AdminPerformance extends AdminTab
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>';
|
</div>';
|
||||||
$servers = MCached::getMemcachedServers();
|
$servers = CacheMemcache::getMemcachedServers();
|
||||||
if ($servers)
|
if ($servers)
|
||||||
{
|
{
|
||||||
echo '<div class="margin-form">
|
echo '<div class="margin-form">
|
||||||
|
|||||||
Vendored
+11
-7
@@ -26,10 +26,6 @@
|
|||||||
'CMS' => 'override/classes/CMS.php',
|
'CMS' => 'override/classes/CMS.php',
|
||||||
'CMSCategoryCore' => 'classes/CMSCategory.php',
|
'CMSCategoryCore' => 'classes/CMSCategory.php',
|
||||||
'CMSCategory' => 'override/classes/CMSCategory.php',
|
'CMSCategory' => 'override/classes/CMSCategory.php',
|
||||||
'CacheCore' => 'classes/Cache.php',
|
|
||||||
'Cache' => 'override/classes/Cache.php',
|
|
||||||
'CacheFSCore' => 'classes/CacheFS.php',
|
|
||||||
'CacheFS' => 'override/classes/CacheFS.php',
|
|
||||||
'CarrierCore' => 'classes/Carrier.php',
|
'CarrierCore' => 'classes/Carrier.php',
|
||||||
'Carrier' => 'override/classes/Carrier.php',
|
'Carrier' => 'override/classes/Carrier.php',
|
||||||
'CarrierModuleCore' => 'classes/CarrierModule.php',
|
'CarrierModuleCore' => 'classes/CarrierModule.php',
|
||||||
@@ -126,8 +122,6 @@
|
|||||||
'LocalizationPack' => 'override/classes/LocalizationPack.php',
|
'LocalizationPack' => 'override/classes/LocalizationPack.php',
|
||||||
'LoggerCore' => 'classes/Logger.php',
|
'LoggerCore' => 'classes/Logger.php',
|
||||||
'Logger' => 'override/classes/Logger.php',
|
'Logger' => 'override/classes/Logger.php',
|
||||||
'MCachedCore' => 'classes/MCached.php',
|
|
||||||
'MCached' => 'override/classes/MCached.php',
|
|
||||||
'MailCore' => 'classes/Mail.php',
|
'MailCore' => 'classes/Mail.php',
|
||||||
'Mail' => 'override/classes/Mail.php',
|
'Mail' => 'override/classes/Mail.php',
|
||||||
'ManufacturerCore' => 'classes/Manufacturer.php',
|
'ManufacturerCore' => 'classes/Manufacturer.php',
|
||||||
@@ -210,7 +204,7 @@
|
|||||||
'SpecificPrice' => 'override/classes/SpecificPrice.php',
|
'SpecificPrice' => 'override/classes/SpecificPrice.php',
|
||||||
'StateCore' => 'classes/State.php',
|
'StateCore' => 'classes/State.php',
|
||||||
'State' => 'override/classes/State.php',
|
'State' => 'override/classes/State.php',
|
||||||
'StockCore' => 'classes/Stock.php',
|
'StockCore' => 'classes/stock/Stock.php',
|
||||||
'Stock' => 'override/classes/Stock.php',
|
'Stock' => 'override/classes/Stock.php',
|
||||||
'StockMvtCore' => 'classes/StockMvt.php',
|
'StockMvtCore' => 'classes/StockMvt.php',
|
||||||
'StockMvt' => 'override/classes/StockMvt.php',
|
'StockMvt' => 'override/classes/StockMvt.php',
|
||||||
@@ -238,6 +232,12 @@
|
|||||||
'Validate' => 'override/classes/Validate.php',
|
'Validate' => 'override/classes/Validate.php',
|
||||||
'ZoneCore' => 'classes/Zone.php',
|
'ZoneCore' => 'classes/Zone.php',
|
||||||
'Zone' => 'override/classes/Zone.php',
|
'Zone' => 'override/classes/Zone.php',
|
||||||
|
'CacheCore' => 'classes/cache/Cache.php',
|
||||||
|
'Cache' => 'override/classes/cache/Cache.php',
|
||||||
|
'CacheFsCore' => 'classes/cache/CacheFs.php',
|
||||||
|
'CacheFs' => 'override/classes/cache/CacheFs.php',
|
||||||
|
'CacheMemcacheCore' => 'classes/cache/CacheMemcache.php',
|
||||||
|
'CacheMemcache' => 'override/classes/cache/CacheMemcache.php',
|
||||||
'DbCore' => 'classes/db/Db.php',
|
'DbCore' => 'classes/db/Db.php',
|
||||||
'Db' => 'override/classes/db/Db.php',
|
'Db' => 'override/classes/db/Db.php',
|
||||||
'DbMySQLiCore' => 'classes/db/DbMySQLi.php',
|
'DbMySQLiCore' => 'classes/db/DbMySQLi.php',
|
||||||
@@ -262,6 +262,10 @@
|
|||||||
'Shop' => 'override/classes/shop/Shop.php',
|
'Shop' => 'override/classes/shop/Shop.php',
|
||||||
'ShopUrlCore' => 'classes/shop/ShopUrl.php',
|
'ShopUrlCore' => 'classes/shop/ShopUrl.php',
|
||||||
'ShopUrl' => 'override/classes/shop/ShopUrl.php',
|
'ShopUrl' => 'override/classes/shop/ShopUrl.php',
|
||||||
|
'StockManagerFactoryCore' => 'classes/stock/StockManagerFactory.php',
|
||||||
|
'StockManagerFactory' => '',
|
||||||
|
'StockManagerInterface' => 'classes/stock/StockManagerInterface.php',
|
||||||
|
'StockManagerModule' => 'classes/stock/StockManagerModule.php',
|
||||||
'TaxCore' => 'classes/tax/Tax.php',
|
'TaxCore' => 'classes/tax/Tax.php',
|
||||||
'Tax' => 'override/classes/tax/Tax.php',
|
'Tax' => 'override/classes/tax/Tax.php',
|
||||||
'TaxCalculatorCore' => 'classes/tax/TaxCalculator.php',
|
'TaxCalculatorCore' => 'classes/tax/TaxCalculator.php',
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 2007-2011 PrestaShop
|
|
||||||
*
|
|
||||||
* NOTICE OF LICENSE
|
|
||||||
*
|
|
||||||
* This source file is subject to the Open Software License (OSL 3.0)
|
|
||||||
* that is bundled with this package in the file LICENSE.txt.
|
|
||||||
* It is also available through the world-wide-web at this URL:
|
|
||||||
* http://opensource.org/licenses/osl-3.0.php
|
|
||||||
* If you did not receive a copy of the license and are unable to
|
|
||||||
* obtain it through the world-wide-web, please send an email
|
|
||||||
* to license@prestashop.com so we can send you a copy immediately.
|
|
||||||
*
|
|
||||||
* DISCLAIMER
|
|
||||||
*
|
|
||||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
||||||
* versions in the future. If you wish to customize PrestaShop for your
|
|
||||||
* needs please refer to http://www.prestashop.com for more information.
|
|
||||||
*
|
|
||||||
* @author PrestaShop SA <contact@prestashop.com>
|
|
||||||
* @copyright 2007-2011 PrestaShop SA
|
|
||||||
* @version Release: $Revision: 6844 $
|
|
||||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
|
||||||
*/
|
|
||||||
|
|
||||||
abstract class CacheCore
|
|
||||||
{
|
|
||||||
/** @var Cache */
|
|
||||||
protected static $_instance;
|
|
||||||
protected $_keysCached = array();
|
|
||||||
protected $_tablesCached = array();
|
|
||||||
protected $_blackList = array('cart',
|
|
||||||
'cart_discount',
|
|
||||||
'cart_product',
|
|
||||||
'connections',
|
|
||||||
'connections_source',
|
|
||||||
'connections_page',
|
|
||||||
'customer',
|
|
||||||
'customer_group',
|
|
||||||
'customized_data',
|
|
||||||
'guest',
|
|
||||||
'pagenotfound',
|
|
||||||
'page_viewed');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Cache
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if(!isset(self::$_instance))
|
|
||||||
{
|
|
||||||
$caching_system = _PS_CACHING_SYSTEM_;
|
|
||||||
self::$_instance = new $caching_system();
|
|
||||||
|
|
||||||
}
|
|
||||||
return self::$_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isBlacklist($query)
|
|
||||||
{
|
|
||||||
foreach ($this->_blackList AS $find)
|
|
||||||
if (strpos($query, $find))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function get($key);
|
|
||||||
abstract public function delete($key, $timeout = 0);
|
|
||||||
abstract public function set($key, $value, $expire = 0);
|
|
||||||
abstract public function flush();
|
|
||||||
abstract public function setQuery($query, $result);
|
|
||||||
abstract public function deleteQuery($query);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 2007-2011 PrestaShop
|
|
||||||
*
|
|
||||||
* NOTICE OF LICENSE
|
|
||||||
*
|
|
||||||
* This source file is subject to the Open Software License (OSL 3.0)
|
|
||||||
* that is bundled with this package in the file LICENSE.txt.
|
|
||||||
* It is also available through the world-wide-web at this URL:
|
|
||||||
* http://opensource.org/licenses/osl-3.0.php
|
|
||||||
* If you did not receive a copy of the license and are unable to
|
|
||||||
* obtain it through the world-wide-web, please send an email
|
|
||||||
* to license@prestashop.com so we can send you a copy immediately.
|
|
||||||
*
|
|
||||||
* DISCLAIMER
|
|
||||||
*
|
|
||||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
||||||
* versions in the future. If you wish to customize PrestaShop for your
|
|
||||||
* needs please refer to http://www.prestashop.com for more information.
|
|
||||||
*
|
|
||||||
* @author PrestaShop SA <contact@prestashop.com>
|
|
||||||
* @copyright 2007-2011 PrestaShop SA
|
|
||||||
* @version Release: $Revision: 6844 $
|
|
||||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CacheFSCore extends Cache {
|
|
||||||
|
|
||||||
protected $_depth;
|
|
||||||
|
|
||||||
protected function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _init()
|
|
||||||
{
|
|
||||||
$this->_depth = Db::getInstance()->getValue('SELECT value FROM '._DB_PREFIX_.'configuration WHERE name=\'PS_CACHEFS_DIRECTORY_DEPTH\'', false);
|
|
||||||
return $this->_setKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($key, $value, $expire = 0)
|
|
||||||
{
|
|
||||||
$path = $this->getPath();
|
|
||||||
for ($i = 0; $i < $this->_depth; $i++)
|
|
||||||
$path .= $key[$i].'/';
|
|
||||||
if (@file_put_contents($path.$key, serialize($value)))
|
|
||||||
{
|
|
||||||
$this->_keysCached[$key] = true;
|
|
||||||
return $key;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNumRows($key, $value, $expire = 0)
|
|
||||||
{
|
|
||||||
return $this->set($key.'_nrows', $value, $expire);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNumRows($key)
|
|
||||||
{
|
|
||||||
return $this->get($key.'_nrows');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if (!isset($this->_keysCached[$key]))
|
|
||||||
return false;
|
|
||||||
$path = $this->getPath();
|
|
||||||
for ($i = 0; $i < $this->_depth; $i++)
|
|
||||||
$path .= $key[$i].'/';
|
|
||||||
if (!file_exists($path.$key))
|
|
||||||
{
|
|
||||||
unset($this->_keysCached[$key]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$file = file_get_contents($path.$key);
|
|
||||||
return unserialize($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _setKeys()
|
|
||||||
{
|
|
||||||
if (file_exists($this->getPath().'keysCached'))
|
|
||||||
{
|
|
||||||
$file = file_get_contents($this->getPath().'keysCached');
|
|
||||||
$this->_keysCached = unserialize($file);
|
|
||||||
}
|
|
||||||
if (file_exists($this->getPath().'tablesCached'))
|
|
||||||
{
|
|
||||||
$file = file_get_contents($this->getPath().'tablesCached');
|
|
||||||
$this->_tablesCached = unserialize($file);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setQuery($query, $result)
|
|
||||||
{
|
|
||||||
$md5_query = md5($query);
|
|
||||||
if ($this->isBlacklist($query))
|
|
||||||
return true;
|
|
||||||
$this->_setKeys();
|
|
||||||
if (isset($this->_keysCached[$md5_query]))
|
|
||||||
return true;
|
|
||||||
$key = $this->set($md5_query, $result);
|
|
||||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
|
||||||
foreach($res[1] AS $table)
|
|
||||||
if(!isset($this->_tablesCached[$table][$key]))
|
|
||||||
$this->_tablesCached[$table][$key] = true;
|
|
||||||
$this->_writeKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($key, $timeout = 0)
|
|
||||||
{
|
|
||||||
$path = $this->getPath();
|
|
||||||
if (!isset($this->_keysCached[$key]))
|
|
||||||
return;
|
|
||||||
for ($i = 0; $i < $this->_depth; $i++)
|
|
||||||
$path.=$key[$i].'/';
|
|
||||||
if (!file_exists($path.$key))
|
|
||||||
return true;
|
|
||||||
if (!unlink($path.$key))
|
|
||||||
return false;
|
|
||||||
unset($this->_keysCached[$key]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteQuery($query)
|
|
||||||
{
|
|
||||||
$this->_setKeys();
|
|
||||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
|
||||||
foreach ($res[1] AS $table)
|
|
||||||
if (isset($this->_tablesCached[$table]))
|
|
||||||
{
|
|
||||||
foreach (array_keys($this->_tablesCached[$table]) AS $fsKey)
|
|
||||||
{
|
|
||||||
$this->delete($fsKey);
|
|
||||||
$this->delete($fsKey.'_nrows');
|
|
||||||
}
|
|
||||||
unset($this->_tablesCached[$table]);
|
|
||||||
}
|
|
||||||
$this->_writeKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function flush()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private function _writeKeys()
|
|
||||||
{
|
|
||||||
|
|
||||||
@file_put_contents($this->getPath().'keysCached', serialize($this->_keysCached));
|
|
||||||
@file_put_contents($this->getPath().'tablesCached', serialize($this->_tablesCached));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function deleteCacheDirectory()
|
|
||||||
{
|
|
||||||
Tools::deleteDirectory($this->getPath(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function createCacheDirectories($level_depth, $directory = false)
|
|
||||||
{
|
|
||||||
if (!$directory)
|
|
||||||
$directory = $this->getPath();
|
|
||||||
$chars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
||||||
for ($i = 0; $i < strlen($chars); $i++)
|
|
||||||
{
|
|
||||||
$new_dir = $directory.$chars[$i].'/';
|
|
||||||
if (mkdir($new_dir))
|
|
||||||
if (chmod($new_dir, 0777))
|
|
||||||
if ($level_depth - 1 > 0)
|
|
||||||
self::createCacheDirectories($level_depth - 1, $new_dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPath()
|
|
||||||
{
|
|
||||||
return (defined('_PS_CACHEFS_DIRECTORY_') ? _PS_CACHEFS_DIRECTORY_ : dirname(__FILE__).'/../cache/cachefs/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* 2007-2011 PrestaShop
|
|
||||||
*
|
|
||||||
* NOTICE OF LICENSE
|
|
||||||
*
|
|
||||||
* This source file is subject to the Open Software License (OSL 3.0)
|
|
||||||
* that is bundled with this package in the file LICENSE.txt.
|
|
||||||
* It is also available through the world-wide-web at this URL:
|
|
||||||
* http://opensource.org/licenses/osl-3.0.php
|
|
||||||
* If you did not receive a copy of the license and are unable to
|
|
||||||
* obtain it through the world-wide-web, please send an email
|
|
||||||
* to license@prestashop.com so we can send you a copy immediately.
|
|
||||||
*
|
|
||||||
* DISCLAIMER
|
|
||||||
*
|
|
||||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
||||||
* versions in the future. If you wish to customize PrestaShop for your
|
|
||||||
* needs please refer to http://www.prestashop.com for more information.
|
|
||||||
*
|
|
||||||
* @author PrestaShop SA <contact@prestashop.com>
|
|
||||||
* @copyright 2007-2011 PrestaShop SA
|
|
||||||
* @version Release: $Revision: 6844 $
|
|
||||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
|
||||||
*/
|
|
||||||
|
|
||||||
class MCachedCore extends Cache
|
|
||||||
{
|
|
||||||
protected $_memcacheObj;
|
|
||||||
protected $_isConnected = false;
|
|
||||||
|
|
||||||
protected function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function connect()
|
|
||||||
{
|
|
||||||
$this->_memcacheObj = new Memcache();
|
|
||||||
$servers = self::getMemcachedServers();
|
|
||||||
if (!$servers)
|
|
||||||
return false;
|
|
||||||
foreach ($servers AS $server)
|
|
||||||
$this->_memcacheObj->addServer($server['ip'], $server['port'], $server['weight']);
|
|
||||||
|
|
||||||
$this->_isConnected = true;
|
|
||||||
return $this->_setKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($key, $value, $expire = 0)
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
if ($this->_memcacheObj->set($key, $value, 0, $expire))
|
|
||||||
{
|
|
||||||
$this->_keysCached[$key] = true;
|
|
||||||
return $key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setNumRows($key, $value, $expire = 0)
|
|
||||||
{
|
|
||||||
return $this->set($key.'_nrows', $value, $expire);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNumRows($key)
|
|
||||||
{
|
|
||||||
return $this->get($key.'_nrows');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if (!isset($this->_keysCached[$key]))
|
|
||||||
return false;
|
|
||||||
return $this->_memcacheObj->get($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function _setKeys()
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
$this->_keysCached = $this->_memcacheObj->get('keysCached');
|
|
||||||
$this->_tablesCached = $this->_memcacheObj->get('tablesCached');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setQuery($query, $result)
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
if ($this->isBlacklist($query))
|
|
||||||
return true;
|
|
||||||
$md5_query = md5($query);
|
|
||||||
$this->_setKeys();
|
|
||||||
if (isset($this->_keysCached[$md5_query]))
|
|
||||||
return true;
|
|
||||||
$key = $this->set($md5_query, $result);
|
|
||||||
if(preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
|
||||||
foreach($res[1] AS $table)
|
|
||||||
if(!isset($this->_tablesCached[$table][$key]))
|
|
||||||
$this->_tablesCached[$table][$key] = true;
|
|
||||||
$this->_writeKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($key, $timeout = 0)
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
if (!empty($key) AND $this->_memcacheObj->delete($key, $timeout))
|
|
||||||
unset($this->_keysCached[$key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteQuery($query)
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
$this->_setKeys();
|
|
||||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
|
||||||
foreach ($res[1] AS $table)
|
|
||||||
if (isset($this->_tablesCached[$table]))
|
|
||||||
{
|
|
||||||
foreach ($this->_tablesCached[$table] AS $memcachedKey => $foo)
|
|
||||||
{
|
|
||||||
$this->delete($memcachedKey);
|
|
||||||
$this->delete($memcachedKey.'_nrows');
|
|
||||||
}
|
|
||||||
unset($this->_tablesCached[$table]);
|
|
||||||
}
|
|
||||||
$this->_writeKeys();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function close()
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
return $this->_memcacheObj->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function flush()
|
|
||||||
{
|
|
||||||
if(!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
if ($this->_memcacheObj->flush())
|
|
||||||
return $this->_setKeys();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function _writeKeys()
|
|
||||||
{
|
|
||||||
if (!$this->_isConnected)
|
|
||||||
return false;
|
|
||||||
$this->_memcacheObj->set('keysCached', $this->_keysCached, 0, 0);
|
|
||||||
$this->_memcacheObj->set('tablesCached', $this->_tablesCached, 0, 0);
|
|
||||||
$this->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function addServer($ip, $port, $weight)
|
|
||||||
{
|
|
||||||
return Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'memcached_servers (ip, port, weight) VALUES(\''.pSQL($ip).'\', '.(int)$port.', '.(int)$weight.')', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getMemcachedServers()
|
|
||||||
{
|
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM '._DB_PREFIX_.'memcached_servers', true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function deleteServer($id_server)
|
|
||||||
{
|
|
||||||
return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'memcached_servers WHERE id_memcached_server='.(int)$id_server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Vendored
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CacheFSCore extends Cache {
|
class CacheFsCore extends Cache {
|
||||||
|
|
||||||
protected $_depth;
|
protected $_depth;
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ $datas = array(
|
|||||||
array('_DB_PASSWD_', trim($_GET['password'])),
|
array('_DB_PASSWD_', trim($_GET['password'])),
|
||||||
array('_DB_PREFIX_', trim($_GET['tablePrefix'])),
|
array('_DB_PREFIX_', trim($_GET['tablePrefix'])),
|
||||||
array('_MYSQL_ENGINE_', trim($_GET['engine'])),
|
array('_MYSQL_ENGINE_', trim($_GET['engine'])),
|
||||||
array('_PS_CACHING_SYSTEM_', 'MCached'),
|
array('_PS_CACHING_SYSTEM_', 'CacheMemcache'),
|
||||||
array('_PS_CACHE_ENABLED_', '0'),
|
array('_PS_CACHE_ENABLED_', '0'),
|
||||||
array('_MEDIA_SERVER_1_', ''),
|
array('_MEDIA_SERVER_1_', ''),
|
||||||
array('_MEDIA_SERVER_2_', ''),
|
array('_MEDIA_SERVER_2_', ''),
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ $datas = array(
|
|||||||
array('_DB_PASSWD_', _DB_PASSWD_),
|
array('_DB_PASSWD_', _DB_PASSWD_),
|
||||||
array('_DB_PREFIX_', _DB_PREFIX_),
|
array('_DB_PREFIX_', _DB_PREFIX_),
|
||||||
array('_MYSQL_ENGINE_', $mysqlEngine),
|
array('_MYSQL_ENGINE_', $mysqlEngine),
|
||||||
array('_PS_CACHING_SYSTEM_', (defined('_PS_CACHING_SYSTEM_') AND _PS_CACHING_SYSTEM_ != 'MemCached') ? _PS_CACHING_SYSTEM_ : 'MCached'),
|
array('_PS_CACHING_SYSTEM_', (defined('_PS_CACHING_SYSTEM_') AND _PS_CACHING_SYSTEM_ != 'CacheMemcache') ? _PS_CACHING_SYSTEM_ : 'CacheMemcache'),
|
||||||
array('_PS_CACHE_ENABLED_', defined('_PS_CACHE_ENABLED_') ? _PS_CACHE_ENABLED_ : '0'),
|
array('_PS_CACHE_ENABLED_', defined('_PS_CACHE_ENABLED_') ? _PS_CACHE_ENABLED_ : '0'),
|
||||||
array('_MEDIA_SERVER_1_', defined('_MEDIA_SERVER_1_') ? _MEDIA_SERVER_1_ : ''),
|
array('_MEDIA_SERVER_1_', defined('_MEDIA_SERVER_1_') ? _MEDIA_SERVER_1_ : ''),
|
||||||
array('_MEDIA_SERVER_2_', defined('_MEDIA_SERVER_2_') ? _MEDIA_SERVER_2_ : ''),
|
array('_MEDIA_SERVER_2_', defined('_MEDIA_SERVER_2_') ? _MEDIA_SERVER_2_ : ''),
|
||||||
@@ -335,8 +335,8 @@ foreach ($arrayToClean as $dir)
|
|||||||
$depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH');
|
$depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH');
|
||||||
if($depth)
|
if($depth)
|
||||||
{
|
{
|
||||||
CacheFS::deleteCacheDirectory();
|
CacheFs::deleteCacheDirectory();
|
||||||
CacheFS::createCacheDirectories((int)$depth);
|
CacheFs::createCacheDirectories((int)$depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sql file execution
|
//sql file execution
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class CacheFS extends CacheFSCore
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class MCached extends MCachedCore
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CacheFs extends CacheFsCore
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CacheMemcache extends CacheMemcacheCore
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user