From 628ac9ec4042d2a11dc4daef0de2aaa0253736a5 Mon Sep 17 00:00:00 2001 From: ed neville Date: Tue, 6 Aug 2024 21:01:32 +0100 Subject: [PATCH] When key is longer than 250 reduce the length If the key is more than 250 characters, reduce it to the first 200, append :redacted: and the md5 of the whole original key. --- object-cache.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/object-cache.php b/object-cache.php index dd2ff80..c94535f 100644 --- a/object-cache.php +++ b/object-cache.php @@ -727,7 +727,13 @@ function key( $key, $group ) { $prefix .= $this->blog_prefix; } - return preg_replace( '/\s+/', '', "$prefix:$group:$key" ); + $trimmed = preg_replace( '/\s+/', '', "$prefix:$group:$key" ); + if ( strlen( $trimmed ) <= 250 ) { + return $trimmed; + } + + $trimmed = substr( $trimmed, 0, 200 ) . ':redacted:' . md5( $trimmed ); + return $trimmed; } function replace( $id, $data, $group = 'default', $expire = 0 ) {