Thinkphp cache proxy CacheDelegate class handles redis without *** CacheDelegate () ** @ parammixed $ cacheHandler * @ parammixed $ cacheName * @ parammixed $ cacheParams * @ parammixed $ GetFunctionDataArray * @ parammixed $ GetFunctionParamArray * @ parammixed
Thinkphp cache proxy CacheDelegate class handles redis without/*** CacheDelegate () ** @ param mixed $ cacheHandler * @ param mixed $ cacheName * @ param mixed $ cacheParams * @ param mixed $ GetFunctionDataArray * @ param mixed $ GetFunctionParamArray * @ param mixed
Thinkphp cache proxy CacheDelegate class handles redis <无>
/*** CacheDelegate () ** @ param mixed $ cacheHandler * @ param mixed $ cacheName * @ param mixed $ cacheParams * @ param mixed $ GetFunctionDataArray * @ param mixed $ GetFunctionParamArray * @ param mixed $ reply * @ param mixed $ DealFunctionParamArray * @ param mixed $ UpdateCache * @ return */function CacheDelegate ($ cacheHandler, $ CacheName, $ cacheParams = array (), $ GetFunctionDataArray = array (), $ GetFunctionParamArray = array (), $ DealFunctionDataArray = array (), $ DealFunctionParamArray = array (), $ UpdateCache = false) {$ cacheValue = ''; if (isset ($ CacheName) {$ cacheSetting = C ('cachetable'); $ cacheSetting = $ cacheSetting [$ CacheName]; $ cacheKey = vsprintf ($ cacheSetting ['cachekey'], $ cacheParams); if (empty ($ cacheKey) {if (APP_STATUS = 'dev _ config ') {throw_exception ("cache configuration file cachetable. in php, $ CacheN Ame configuration error ");} return null;} $ expire = $ cacheSetting ['expire ']? $ CacheSetting ['expire ']: null; $ keyCached = $ cacheHandler-> exists ($ cacheKey); if ($ keyCached) {$ cacheValue = $ cacheHandler-> get ($ cacheKey);} // if keyCached is set to false, the cache does not exist and you need to read the database again. if (! $ KeyCached | $ UpdateCache) {if (isset ($ GetFunctionDataArray) & is_callable ($ GetFunctionDataArray) {$ cacheValue = call_user_func_array ($ GetFunctionDataArray, $ GetFunctionParamArray ); if (isset ($ cacheValue) {$ cacheHandler-> set ($ cacheKey, $ cacheValue, $ expire) ;}} if (isset ($ DealFunctionDataArray) & is_callable ($ DealFunctionDataArray) {$ DealFunctionParamArray = array_merge (array ($ cacheValue), $ DealFunct IonParamArray); $ TmpcacheValue = values ($ DealFunctionDataArray, $ DealFunctionParamArray); if (isset ($ cacheValue) {$ cacheHandler-> set ($ cacheKey, $ TmpcacheValue, $ expire ); $ cacheValue = $ TmpcacheValue; }}return $ cacheValue;}/*** string truncation, supports Chinese and other encodings * @ static * @ access public * @ param string $ str string to be converted * @ param string $ start position * @ param string $ length truncation length *@ param string $ charset encoding format * @ Param string $ suffix truncation display character * @ return string */function msubstr ($ str, $ start = 0, $ length, $ charset = "UTF-8", $ suffix = true) {if (function_exists ("mb_substr") $ slice = mb_substr ($ str, $ start, $ length, $ charset); elseif (function_exists ('iconv _ substr ')) {$ slice = iconv_substr ($ str, $ start, $ length, $ charset); if (false ===$ slice) {$ slice = '';}} else {$ re ['utf-8'] = "/[\ x01-\ x7f] | [\ xc2-\ xdf] [\ x80-\ xbf] | [\ xe0- \ Xef] [\ x80-\ xbf] {2} | [\ xf0-\ xff] [\ x80-\ xbf] {3 }/"; $ re ['gb2312'] = "/[\ x01-\ x7f] | [\ xb0-\ xf7] [\ xa0-\ xfe]/"; $ re ['gbk'] = "/[\ x01-\ x7f] | [\ x81-\ xfe] [\ x40-\ xfe]/"; $ re ['big5'] = "/[\ x01-\ x7f] | [\ x81-\ xfe] ([\ x40-\ x7e] | \ xa1-\ xfe]) /"; preg_match_all ($ re [$ charset], $ str, $ match); $ slice = join (" ", array_slice ($ match [0], $ start, $ length) ;}$ fix = ''; if (strlen ($ slice) <strlen ($ str) {$ fix = '... ';} return $ suffix? $ Slice. $ fix: $ slice;}/*** obtain the source IP address * @ return Ambigous
*/Function get_ip () {if (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP"), "unknown ")) $ ip = getenv ("HTTP_CLIENT_IP"); else if (getenv ("HTTP_X_FORWARDED_FOR") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR"), "unknown ")) $ ip = getenv ("HTTP_X_FORWARDED_FOR"); else if (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "unknown ")) $ ip = getenv ("REMOTE_ADDR"); else if (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], "unknown ")) $ ip = $ _ SERVER ['remote _ ADDR ']; else $ ip = "unknown"; return ($ ip );}