yii\caching\Cache::buildKey PHP Method

buildKey() public method

If the given key is a string containing alphanumeric characters only and no more than 32 characters, then the key will be returned back prefixed with [[keyPrefix]]. Otherwise, a normalized key is generated by serializing the given key, applying MD5 hashing, and prefixing with [[keyPrefix]].
public buildKey ( mixed $key ) : string
$key mixed the key to be normalized
return string the generated cache key
    public function buildKey($key)
    {
        if (is_string($key)) {
            $key = ctype_alnum($key) && StringHelper::byteLength($key) <= 32 ? $key : md5($key);
        } else {
            $key = md5(json_encode($key));
        }
        return $this->keyPrefix . $key;
    }

Usage Example

コード例 #1
0
ファイル: Cache.php プロジェクト: urbanindo/yii2-s3cache
 /**
  * Builds a normalized cache key from a given key.
  *
  * This will baypass if the we don't want to normalize the key.
  *
  * @param mixed $key the key to be normalized
  * @return string the generated cache key
  */
 public function buildKey($key)
 {
     if (!is_string($key) || $this->hashKey) {
         return parent::buildKey($key);
     }
     return $this->keyPrefix . $key;
 }
All Usage Examples Of yii\caching\Cache::buildKey