Commit 31318ba4 authored by Hannes Peterseim's avatar Hannes Peterseim

Änderungen für mehr Speed, Dank an Walter Gerling von Design3000

parent 0750372b
......@@ -13,8 +13,11 @@ Redis : redis-server wird auf dem System ebenso wie php-redis vorausgesetzt.
## Sicherheit
Sollten Seiteneffekte auftreten kann der Cachingservice im Administrationsbereich und im Checkout dediziert abgeschaltet werden.
Aus Sicheheitsgründen ist das die Standardeinstellung.
Aus Sicherheitsgründen ist das die Standardeinstellung.
## Schwierigkeiten bei der Installation?
Gerne helfe ich bei der Installation von Memcache oder Redis und der Einrichtung dieses Modules.
Sie erreichen mich unter oxid@petit-souris.de.
\ No newline at end of file
Sie erreichen mich unter oxid@petit-souris.de.
## Verbesserungen von
Waldemar Gerling von design3000
\ No newline at end of file
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -40,8 +41,8 @@ class oxOnRoidsOxAmountPriceList extends oxOnRoidsOxAmountPriceList_parent
$sSql = "SELECT * FROM `oxprice2article` WHERE `oxartid` = " . oxDb::getDb()->quote($sArticleId) . " AND $sShopSelect ORDER BY `oxamount` ";
$this->cS = new cacheService();
$aData = $this->cS->getData($sSql,'amountpricelist','all');
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSql, 'amountpricelist', 'all');
return $aData;
}
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -29,11 +30,10 @@ class oxOnRoidsOxArticle extends oxOnRoidsOxArticle_parent
*/
protected function _loadFromDb($sOXID)
{
$sSelect = $this->buildSelectString(array($this->getViewName() . ".oxid" => $sOXID));
$this->cS = new cacheService();
$aData = $this->cS->getData($sSelect,'article','row');
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSelect, 'article', 'row');
return $aData;
}
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -31,7 +32,7 @@ class oxOnRoidsOxCategory extends oxOnRoidsOxCategory_parent
{
$sSelect = $this->buildSelectString(array("`{$this->getViewName()}`.`oxid`" => $sOXID));
$this->cS = new cacheService();
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSelect,'category','row');
return $aData;
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -29,7 +30,7 @@ class oxOnRoidsOxCategoryList extends oxOnRoidsOxCategoryList_parent
{
$sSql = $this->_getSelectString(false, null, 'oxparentid, oxsort, oxtitle');
$this->cS = new cacheService();
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSql,'categorylist','all');
return $aData;
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -55,8 +56,13 @@ class oxOnRoidsOxContent extends oxOnRoidsOxContent_parent
$sSelect = str_replace("`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect);
}
$this->cS = new cacheService();
$aData = $this->cS->getData($sSelect,'content','row');
try {
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSelect, 'content', 'row');
} catch (Exception $oEx) {
return parent::_loadFromDb($sLoadId);
}
return $aData;
}
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -20,7 +21,6 @@ class oxOnRoidsOxContentList extends oxOnRoidsOxContentList_parent
*/
private $cS = null;
/**
* Get data from db
*
......@@ -30,9 +30,15 @@ class oxOnRoidsOxContentList extends oxOnRoidsOxContentList_parent
*/
protected function _loadFromDb($iType)
{
$sSql = $this->_getSQLByType($iType);
$sSQLAdd = '';
if ( $iType == self::TYPE_CATEGORY_MENU ) {
$sSQLAdd = ' AND `oxcatid` IS NOT NULL';
}
$sViewName = $this->getBaseObject()->getViewName();
$sSql = "SELECT * FROM {$sViewName} WHERE `oxactive` = '1' AND `oxtype` = '$iType' AND `oxsnippet` = '0' AND `oxshopid` = '$this->_sShopID' $sSQLAdd ORDER BY `oxloadid`";
$this->cS = new cacheService();
$this->cS = oxRegistry::get('cacheService');
$aData = $this->cS->getData($sSql,'contentlist','all');
return $aData;
......
......@@ -24,7 +24,6 @@ class oxOnRoidsOxList extends oxOnRoidsOxList_parent
*/
private $cS = null;
/**
* Selects and SQL, creates objects and assign them
*
......@@ -33,7 +32,7 @@ class oxOnRoidsOxList extends oxOnRoidsOxList_parent
public function selectString($sSql)
{
$this->cS = new cacheService();
$this->cS = oxRegistry::get('cacheService');
$this->myConfig = oxRegistry::getConfig();
if ($this->cS) {
......@@ -118,8 +117,10 @@ class oxOnRoidsOxList extends oxOnRoidsOxList_parent
$oDb = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
if ($this->_aSqlLimit[0] || $this->_aSqlLimit[1]) {
return $oDb->selectLimit($sSql, $this->_aSqlLimit[1], $this->_aSqlLimit[0]);
} else {
return $oDb->select($sSql);
}
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -23,12 +25,12 @@ class oxOnRoidsOxSeoEncoder extends oxOnRoidsOxSeoEncoder_parent
* _loadFromDb loads data from oxseo table if exists
* returns oxseo url
*
* @param string $sType object type
* @param string $sId object identifier
* @param int $iLang active language id
* @param mixed $iShopId active shop id
* @param string $sParams additional seo params. optional (mostly used for db indexing)
* @param bool $blStrictParamsCheck strict parameters check
* @param string $sType object type
* @param string $sId object identifier
* @param int $iLang active language id
* @param mixed $iShopId active shop id
* @param string $sParams additional seo params. optional (mostly used for db indexing)
* @param bool $blStrictParamsCheck strict parameters check
*
* @access protected
*
......@@ -41,7 +43,7 @@ class oxOnRoidsOxSeoEncoder extends oxOnRoidsOxSeoEncoder_parent
$iShopId = $this->getConfig()->getShopId();
}
$iLang = (int) $iLang;
$iLang = (int)$iLang;
$oDb = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
$sQ = "
......@@ -64,8 +66,8 @@ class oxOnRoidsOxSeoEncoder extends oxOnRoidsOxSeoEncoder_parent
}
$sQ .= " LIMIT 1";
$this->cS = new cacheService();
$oRs = $this->cS->getData($sQ,'seoencoder','select');
$this->cS = oxRegistry::get('cacheService');
$oRs = $this->cS->getData($sQ, 'seoencoder', 'select');
if ($oRs && $oRs->recordCount() > 0 && !$oRs->EOF) {
// moving expired static urls to history ..
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -14,6 +15,16 @@
class cacheService
{
private static $_instance = null;
public static function getInstance()
{
if (false == self::$_instance instanceof cacheService) {
self::$_instance = oxNew('cacheService');
}
return self::$_instance;
}
/**
* @var null
*/
......@@ -28,7 +39,7 @@ class cacheService
/**
* @var array
*/
private $checkoutClasses = array('basket','user','payment','order','thankyou');
private $checkoutClasses = array('basket', 'user', 'payment', 'order', 'thankyou');
/**
* @param $sSql
......@@ -37,20 +48,31 @@ class cacheService
*
* @return array|false|mixed|object|string
*/
public function getData($sSql, $dataType, $getType) {
public function getData($sSql, $dataType, $getType, $aLimit = array())
{
$this->myConfig = oxRegistry::getConfig();
if (!$this->denyForCheckout() && !$this->denyForAdminArea()) {
if ($this->myConfig->getConfigParam('oorCachingBackend') == 'Memcache') {
$this->cS = new memcacheConnector();
} else {
if ($this->myConfig->getConfigParam('oorCachingBackend') == 'Redis') {
$this->cS = new redisConnector();
if (!$this->denyForCheckout() && !$this->denyForAdminArea() && !$this->denyByParam()) {
if ($this->cS === null) {
if ($oConfig->getConfigParam('oorCachingBackend') == 'Memcache') {
$this->cS = new memcacheConnector();
} else {
if ($oConfig->getConfigParam('oorCachingBackend') == 'Redis') {
$this->cS = new redisConnector();
}
}
}
if ($this->cS) {
$cSKey = $dataType . '_' . $this->myConfig->getShopId() . '_' . md5($sSql);
if (count($aLimit) > 0) {
$dataType .= "_{$aLimit[1]}/{$aLimit[0]}";
}
$cSKey = $dataType . '_' . $myConfig->getShopId() . '_' . md5($sSql);
if ($this->cS->get($cSKey)) {
if ($this->myConfig->getConfigParam('oorShowDebug')) {
echo $dataType . '_hit';
......@@ -60,80 +82,103 @@ class cacheService
if ($this->myConfig->getConfigParam('oorShowDebug')){
echo $dataType . '_fill';
}
if ($getType == 'all') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getAll($sSql);
}
if ($getType == 'row') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSql);
}
if ($getType == 'one') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sSql);
}
if ($getType == 'select') {
$aData = oxDb::getDb()->select($sSql);
}
$this->cS->set($cSKey, serialize($aData),$this->myConfig->getConfigParam('oor' . ucfirst($dataType) . 'Ttl'));
$aData = $this->_execQuery($getType, $sSql, $aLimit);
$this->cS->set($cSKey, serialize($aData), $oConfig->getConfigParam('oor' . ucfirst($dataType) . 'Ttl'));
}
} else {
if ($this->myConfig->getConfigParam('oorShowDebug')) {
echo $dataType . '_cacheservice_gone';
}
if ($getType == 'all') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getAll($sSql);
}
if ($getType == 'row') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSql);
}
if ($getType == 'one') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sSql);
}
if ($getType == 'select') {
$aData = oxDb::getDb()->select($sSql);
}
$aData = $this->_execQuery($getType, $sSql, $aLimit);
}
} else {
if ($this->myConfig->getConfigParam('oorShowDebug')) {
echo $dataType . '_service denied';
}
if ($getType == 'all') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getAll($sSql);
}
if ($getType == 'row') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSql);
}
if ($getType == 'one') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sSql);
}
if ($getType == 'select') {
$aData = oxDb::getDb()->select($sSql);
}
$aData = $this->_execQuery($getType, $sSql, $aLimit);
}
return $aData;
}
/**
* @param $getType select type
* @param $sSql sql query
*
* @return mixed
*/
protected function _execQuery($getType, $sSql, $aLimit = false)
{
if ($getType == 'all') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getAll($sSql);
}
if ($getType == 'row') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSql);
}
if ($getType == 'one') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sSql);
}
if ($getType == 'array') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getArray($sSql);
}
if ($getType == 'select') {
$aData = oxDb::getDb()->select($sSql);
}
if ($getType == 'select-assoc') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->select($sSql);
}
if ($getType == 'select-assoc-limit') {
$aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->selectLimit($sSql, $aLimit[1], $aLimit[0]);
}
return $aData;
}
/**
* @return bool
*/
private function denyForAdminArea() {
private function denyForAdminArea()
{
$this->myConfig = oxRegistry::getConfig();
if ($this->myConfig->getConfigParam('oorNotForAdmin') && $this->myConfig->isAdmin()) {
return true;
return true;
}
return false;
return false;
}
/**
* @return bool
*/
private function denyForCheckout() {
if ($this->myConfig->getConfigParam('oorNotForCheckout') && in_array($this->myConfig->getActiveView()->getClassName(),$this->checkoutClasses)) {
return true;
private function denyForCheckout()
{
$this->myConfig = oxRegistry::getConfig();
if ($this->myConfig->getConfigParam('oorNotForCheckout') && in_array($this->myConfig->getActiveView()->getClassName(), $this->checkoutClasses)) {
return true;
}
return false;
}
/**
* @return bool
*/
private function denyByParam()
{
if (isset($_GET['nocache'])) {
return true;
}
return false;
}
......@@ -184,7 +229,7 @@ class cacheService
}
}
if ($this->cS) {
$this->cS->set($key,$value,$expires);
$this->cS->set($key, $value, $expires);
}
}
}
......
......@@ -31,6 +31,7 @@ class memcacheConnector
{
$this->myConfig = oxRegistry::getConfig();
$this->mcC = new Memcached;
return $this->mcC->addServer($this->myConfig->getConfigParam('oorMcServer'), $this->myConfig->getConfigParam('oorMcPort'));
}
......@@ -39,8 +40,9 @@ class memcacheConnector
*
* @return mixed
*/
public function get ($key)
public function get($key)
{
return $this->mcC->get($key);
}
......@@ -51,9 +53,10 @@ class memcacheConnector
*
* @return bool
*/
public function set ($key, $value, $expires)
public function set($key, $value, $expires)
{
return $this->mcC->set($key,$value,$expires);
return $this->mcC->set($key, $value, $expires);
}
}
......
<?php
/**
* Copyright 2017 by Hannes Peterseim
* Contribution by Waldemar Gerling
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
......@@ -41,14 +42,9 @@ class redisConnector
*
* @return mixed
*/
public function get ($key)
public function get($key)
{
if ($this->rC->exists($key)) {
return $this->rC->get($key);
}
return false;
return $this->rC->get($key);
}
/**
......@@ -58,9 +54,9 @@ class redisConnector
*
* @return bool
*/
public function set ($key, $value, $expires)
public function set($key, $value, $expires)
{
return $this->rC->setex($key,$expires,$value);
return $this->rC->setex($key, $expires, $value);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment