Changeset 8901 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php
- Timestamp:
- 05/31/2019 06:33:07 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php
r8897 r8901 230 230 $response = wp_cache_get( $cache_key, self::CACHE_GROUP ); 231 231 232 // Use a temporary lock to prevent cache stampedes. This ensures only one process (per search term per memcache instance) will run the remote post. 232 233 // Use a temporary lock to prevent cache stampedes. 234 // This will ensure that a maximum of two processes are performing the search, or one when the stale value is still known. 233 235 // Other processes will use the stale cached value if it's present, even for a while after the expiration time if a fresh value is still being fetched. 236 $do_fresh_request = false; 234 237 if ( wp_cache_add( $lock_key, 1, self::CACHE_GROUP, 15 ) ) { 238 $do_fresh_request = true; 239 } elseif ( ! $response && 2 === wp_cache_incr( $lock_key, 1, self::CACHE_GROUP ) ) { 240 // If we don't have cached data, this is the second request and, error volume is low, still perform the request. 241 $do_fresh_request = $this->error_volume_is_low(); 242 } 243 244 if ( $do_fresh_request ) { 235 245 // Keep track of the number of concurrent requests for this key 236 246 wp_cache_set( $count_key, 1, self::CACHE_GROUP, 60 ); … … 257 267 258 268 // Lock further requests for the same search for 3-7 seconds. We probably don't need anything more complex like exponential backoff here because this is per search. 259 wp_cache_set( $lock_key, 1, self::CACHE_GROUP, mt_rand( 3, 7 ) );269 wp_cache_set( $lock_key, 2, self::CACHE_GROUP, mt_rand( 3, 7 ) ); 260 270 261 271 if ( is_wp_error( $request ) ) {
Note: See TracChangeset
for help on using the changeset viewer.