Skip to content

Commit b9d67ac

Browse files
committed
Method for generating cache key to avoid errors.
1 parent ca59c75 commit b9d67ac

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/wp-includes/collaboration/class-wp-collaboration-table-storage.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public function add_update( string $room, $update ): bool {
7676
return false !== $result;
7777
}
7878

79+
/**
80+
* Generates a cache key for awareness data for a given room.
81+
*
82+
* @since 7.0.0
83+
*
84+
* @param string $room Room identifier.
85+
* @return string Cache key for the room's awareness data.
86+
*/
87+
public function get_awareness_cache_key( string $room ): string {
88+
return 'awareness::' . str_replace( '/', ':', $room );
89+
}
90+
7991
/**
8092
* Gets awareness state for a given room.
8193
*
@@ -103,7 +115,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
103115

104116
$cutoff_timestamp = time() - $timeout;
105117
$cutoff_mysql = gmdate( 'Y-m-d H:i:s', $cutoff_timestamp );
106-
$cache_key = 'awareness::' . str_replace( '/', ':', $room );
118+
$cache_key = $this->get_awareness_cache_key( $room );
107119
$cached = wp_cache_get( $cache_key, 'collaboration' );
108120

109121
if ( false !== $cached && is_array( $cached ) ) {
@@ -350,7 +362,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
350362

351363
$now_timestamp = (int) ceil( time() / $granularity ) * $granularity;
352364
$now_mysql = gmdate( 'Y-m-d H:i:s', $now_timestamp );
353-
$cache_key = 'awareness::' . str_replace( '/', ':', $room );
365+
$cache_key = $this->get_awareness_cache_key( $room );
354366

355367
if ( wp_using_ext_object_cache() ) {
356368
$awareness = $this->get_awareness_state( $room );

0 commit comments

Comments
 (0)