选择语言 :

 Core_Model::_get_cache_key

根据trace获取唯一key

string Core_Model::_get_cache_key( Exception $e [, int $trace_offset = integer 0 ] )

参数列表

参数 类型 描述 默认值
$e Exception $e
$trace_offset int 需要获取key的参照位置,>=0,默认0,通常都是0 integer 0
返回值
  • string
File: ./core/classes/model.class.php
protected function _get_cache_key(Exception $e, $trace_offset = 0)
{
    $trace_offset = (int)$trace_offset;
    if ( !($trace_offset >= 0) )
    {
        $trace_offset = 0;
    }
    $trace = $e->getTrace();
    if ( $trace[$trace_offset]['args'] )
    {
        if ( $this->cache_key_data )
        {
            $trace[$trace_offset]['args'] = array_merge($this->cache_key_data , $trace[$trace_offset]['args'] );
        }

        foreach ( $trace[$trace_offset]['args'] as & $item )
        {
            if ( is_object($item) )
            {
                # 如果是对象,则需要稍微处理下
                if ( $item instanceof OOP_ORM_Data )
                {
                    # ORM DB对象
                    $id_field = $item->id_field_name();
                    if ( $id_field && $item->$id_field )
                    {
                        # 依据唯一ID来设置数据
                        $item = '__ORM_DATA_CLASS:' . get_class($item) . '_ID:' . $item->$id_field;
                    }
                    else
                    {
                        $item = $item->get_field_data();
                    }
                    continue;
                }
            }
        }
    }
    $data = array
    (
        $trace[$trace_offset]['class'],
        $trace[$trace_offset]['function'],
        $trace[$trace_offset]['type'],
        $trace[$trace_offset]['args']
    );

    $this->cache_last_key = 'Model_Cache_' . md5('autokey_' . serialize($data));

    return $this->cache_last_key;
}