refactor: implement centralized cache key management and add utility traits for vCenter SSH operations.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Cache;
|
||||
|
||||
final class CacheKey
|
||||
{
|
||||
/**
|
||||
* Build a canonical cache key.
|
||||
*
|
||||
* Format: module:type[:param:value[:param:value...]]
|
||||
*
|
||||
* Examples:
|
||||
* CacheKey::build('students', 'list', ['page' => 1])
|
||||
* => "students:list:page:1"
|
||||
*
|
||||
* CacheKey::build('students', 'list', ['status' => 'active', 'page' => 2])
|
||||
* => "students:list:page:2:status:active" (sorted by key)
|
||||
*
|
||||
* CacheKey::build('students', 'detail', ['id' => 15])
|
||||
* => "students:detail:id:15"
|
||||
*/
|
||||
public static function build(string $module, string $type, array $params = []): string
|
||||
{
|
||||
ksort($params);
|
||||
|
||||
$parts = [$module, $type];
|
||||
|
||||
foreach ($params as $param => $value) {
|
||||
$parts[] = (string) $param;
|
||||
$parts[] = is_array($value) ? implode(',', $value) : (string) $value;
|
||||
}
|
||||
|
||||
return implode(':', $parts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user