Skip to content

Commit 3bbb01f

Browse files
committed
Let the cache determine how to cache arrays.
1 parent 2023bfd commit 3bbb01f

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
106106
$cache_key = 'awareness::' . str_replace( '/', ':', $room );
107107
$cached = wp_cache_get( $cache_key, 'collaboration' );
108108

109-
if ( false !== $cached && is_string( $cached ) ) {
110-
// Room is cached.
111-
$cached = json_decode( $cached, true );
112-
109+
if ( false !== $cached && is_array( $cached ) ) {
113110
// Deterministic ordering.
114111
$cached_awareness = wp_list_sort( $cached, 'client_id' );
115112

@@ -121,6 +118,9 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
121118
}
122119

123120
return array_values( $cached_awareness );
121+
} elseif ( false !== $cached ) {
122+
// Cache is corrupted, delete it.
123+
wp_cache_delete( $cache_key, 'collaboration' );
124124
}
125125

126126
if ( wp_using_ext_object_cache() ) {
@@ -138,7 +138,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
138138

139139
if ( ! is_array( $rows ) ) {
140140
$entries = array();
141-
wp_cache_set( $cache_key, wp_json_encode( $entries ), 'collaboration' );
141+
wp_cache_set( $cache_key, $entries, 'collaboration', HOUR_IN_SECONDS );
142142
return $entries;
143143
}
144144

@@ -155,7 +155,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
155155
}
156156
}
157157

158-
wp_cache_set( $cache_key, wp_json_encode( $entries ), 'collaboration' );
158+
wp_cache_set( $cache_key, $entries, 'collaboration', HOUR_IN_SECONDS );
159159
return $entries;
160160
}
161161

@@ -378,7 +378,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
378378

379379
// Sort awareness entries by client_id.
380380
$awareness = wp_list_sort( $awareness, 'client_id' );
381-
wp_cache_set( $cache_key, wp_json_encode( $awareness ), 'collaboration', HOUR_IN_SECONDS );
381+
wp_cache_set( $cache_key, $awareness, 'collaboration', HOUR_IN_SECONDS );
382382

383383
return true;
384384
}

0 commit comments

Comments
 (0)