class My_Model_ModuleSettings extends My_Db_Table_Abstract
class My_Db_Table_Abstract extends Zend_Db_Table_Abstract
public function __call($name, $arguments)
{
/** If call cached method */
if (preg_match( '/^cached_(.+)$/' , $name, $methodName)&&method_exists($ this ,$methodName[1])) {
/** Get cache instance */
$cache = My_Cache::getInstance();
/** Get arguments hash */
$argHash = md5(print_r($arguments, true ));
/** Get model class name */
$className = get_class($ this );
/** If method result don't cached */
if (!$result = $cache->load( 'model_' .$className. '_' .$methodName[1]. '_' .$argHash)) {
$result = call_user_method_array($methodName[1], $ this , $arguments);
$cache->save($result,
'model_' .$className. '_' .$methodName[1]. '_' .$argHash,
array( 'model' ,$className,$methodName[1]));
}
return $result;
} else {
/** Generate exception */
throw new Exception( 'Call to undefined method ' .$name);
}
}
$result = $ this ->_life->getAll( 'Now!!' );
$result = $ this ->_life->cached_getAll( 'Now!!' );
$argHash = md5(print_r($arguments));
This is perhaps the most ambiguous moment, because I can not say exactly how this may affect performance (when testing, an increase in load was not noticed). You can use different hashing functions (md5 (), sha1 () ..) and different ways of converting an array of variables to a string type (print_r (), var_dump (), implode ()).$cache->clean(
Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG,
array( 'My_Model_ModuleSettings' )
);
Source: https://habr.com/ru/post/72828/
All Articles