@@ -101,26 +101,12 @@ public function add_update( string $room, $update ): bool {
101101 */
102102 public function get_awareness_state ( string $ room ): array {
103103 $ room_hash = md5 ( $ room );
104- $ cache_key = "sync_awareness_ {$ room_hash }" ;
105- $ cached = wp_cache_get ( $ cache_key , 'sync ' );
106-
107- if ( is_array ( $ cached ) ) {
108- return array_values ( $ cached );
109- }
110-
111- $ post_id = $ this ->get_storage_post_id ( $ room );
112- if ( null === $ post_id ) {
113- return array ();
114- }
115-
116- $ awareness = get_post_meta ( $ post_id , self ::AWARENESS_META_KEY , true );
104+ $ awareness = get_transient ( "sync_awareness_ {$ room_hash }" );
117105
118106 if ( ! is_array ( $ awareness ) ) {
119107 return array ();
120108 }
121109
122- wp_cache_set ( $ cache_key , $ awareness , 'sync ' , MINUTE_IN_SECONDS );
123-
124110 return array_values ( $ awareness );
125111 }
126112
@@ -135,33 +121,7 @@ public function get_awareness_state( string $room ): array {
135121 */
136122 public function set_awareness_state ( string $ room , array $ awareness ): bool {
137123 $ room_hash = md5 ( $ room );
138- $ cache_key = "sync_awareness_ {$ room_hash }" ;
139-
140- /**
141- * Cache the awareness state to reduce post meta reads and writes.
142- *
143- * Awareness is inherently ephemeral and is not critical for
144- * content consistency, so it's acceptable for it to be stale
145- * or missing for a short period of time.
146- *
147- * For sites without object caching, fall back to post meta.
148- */
149- wp_cache_set ( $ cache_key , $ awareness , 'sync ' , MINUTE_IN_SECONDS );
150- if ( wp_using_ext_object_cache () ) {
151- return true ;
152- }
153-
154- $ post_id = $ this ->get_storage_post_id ( $ room );
155-
156- if ( null === $ post_id ) {
157- return false ;
158- }
159-
160- // update_post_meta returns false if the value is the same as the existing value.
161- $ this ->with_suspended_posts_last_changed_update (
162- fn () => update_post_meta ( $ post_id , self ::AWARENESS_META_KEY , $ awareness )
163- );
164- return true ;
124+ return set_transient ( "sync_awareness_ {$ room_hash }" , $ awareness , MINUTE_IN_SECONDS );
165125 }
166126
167127 /**
0 commit comments