ETag
Entity Tag
An HTTP header providing a unique identifier for a specific version of a resource, used for cache validation.
技术细节
RFC 9562 defines ETag versions 1-8. Version 4 (random) is most common: 122 random bits yield a collision probability of ~10^-18 per billion IDs. Version 7 (2024) combines a Unix timestamp millisecond prefix with random bits, producing time-sortable UUIDs ideal for database primary keys. The standard format is 8-4-4-4-12 hexadecimal characters (32 hex digits, 4 hyphens). Database storage is most efficient as BINARY(16) rather than CHAR(36) — saving 20 bytes per row.
示例
```javascript
// Generate UUID v4 (cryptographically random)
const uuid = crypto.randomUUID();
// → 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d'
// Validate UUID format
const isValid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid);
```