示例#1
0
文件: helper.php 项目: Burick/moodle
 /**
  * Hashes a descriptive key to make it shorter and still unique.
  * @param string|int $key
  * @param cache_definition $definition
  * @return string
  */
 public static function hash_key($key, cache_definition $definition)
 {
     if ($definition->uses_simple_keys()) {
         if (debugging() && preg_match('#[^a-zA-Z0-9_]#', $key)) {
             throw new coding_exception('Cache definition ' . $definition->get_id() . ' requires simple keys. Invalid key provided.', $key);
         }
         // We put the key first so that we can be sure the start of the key changes.
         return (string) $key . '-' . $definition->generate_single_key_prefix();
     }
     $key = $definition->generate_single_key_prefix() . '-' . $key;
     return sha1($key);
 }