[+] Classes: add local cache system
This commit is contained in:
1 parent
727b540ce2
commit
cf7301884c
3 files changed
+35
-14
No files matched your search
+1
-7
@@ -134,13 +134,7 @@ class AddressCore extends ObjectModel
|
|||||||
|
|
||||||
/* Get and cache address country name */
|
/* Get and cache address country name */
|
||||||
if ($this->id)
|
if ($this->id)
|
||||||
{
|
$this->country = Country::getNameById($id_lang ? $id_lang : Configuration::get('PS_LANG_DEFAULT'), $this->id_country);
|
||||||
$result = Db::getInstance()->getRow('
|
|
||||||
SELECT `name` FROM `'._DB_PREFIX_.'country_lang`
|
|
||||||
WHERE `id_country` = '.(int)$this->id_country.'
|
|
||||||
AND `id_lang` = '.($id_lang ? (int)$id_lang : Configuration::get('PS_LANG_DEFAULT')));
|
|
||||||
$this->country = $result['name'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $null_values = false)
|
public function add($autodate = true, $null_values = false)
|
||||||
|
|||||||
+9
-7
@@ -214,14 +214,16 @@ class CountryCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public static function getNameById($id_lang, $id_country)
|
public static function getNameById($id_lang, $id_country)
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$key = $id_country.'_'.$id_lang;
|
||||||
SELECT `name`
|
if (!Cache::isStored($key))
|
||||||
FROM `'._DB_PREFIX_.'country_lang`
|
Cache::store($key, Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
WHERE `id_lang` = '.(int)$id_lang.'
|
SELECT `name`
|
||||||
AND `id_country` = '.(int)$id_country
|
FROM `'._DB_PREFIX_.'country_lang`
|
||||||
);
|
WHERE `id_lang` = '.(int)$id_lang.'
|
||||||
|
AND `id_country` = '.(int)$id_country
|
||||||
|
));
|
||||||
|
|
||||||
return $result['name'];
|
return Cache::retrieve($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Vendored
+25
@@ -70,6 +70,11 @@ abstract class CacheCore
|
|||||||
'page_viewed',
|
'page_viewed',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Store local cache
|
||||||
|
*/
|
||||||
|
protected static $local = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache a data
|
* Cache a data
|
||||||
*
|
*
|
||||||
@@ -291,4 +296,24 @@ abstract class CacheCore
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function store($key, $value)
|
||||||
|
{
|
||||||
|
Cache::$local[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function retrieve($key)
|
||||||
|
{
|
||||||
|
return isset(Cache::$local[$key]) ? Cache::$local[$key] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isStored($key)
|
||||||
|
{
|
||||||
|
return isset(Cache::$local[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function clean($key)
|
||||||
|
{
|
||||||
|
unset(Cache::$local[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user