WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#15543 closed defect (bug) (fixed)

_get_last_post_time() uses the incorrect cache key

Reported by: mdawaffe Owned by: scribu
Milestone: 3.1 Priority: high
Severity: major Version:
Component: Cache API Keywords:
Focuses: Cc:

Description

[15838] sets the cache key to

"lastpost{$field}:" . get_current_blog_id() . ":$timezone:" . md5( serialize( $post_types ) )

but that key is never invalidated. The invalidation is meant to be handled by _transition_post_status().

There's no need to explicitly include the blog_id in a cache key.

If the data needs to be cached by some dynamic variable ($post_types, in this case), there are a few options.

  1. The invalidation needs to be a lot smarter (hard).
  2. The cached data needs to be an array ($data[ serialize( ... ) ] = $date) so that it can be invalidated all at once (bad - leads to race conditions).
  3. The data should only be cached for one single page load (wp_cache_add_non_persistent_groups()).
  4. Something else?

Change History (8)

comment:1 nacin3 years ago

  • Component changed from General to Cache
  • Milestone changed from Awaiting Review to 3.1
  • Priority changed from normal to high
  • Severity changed from normal to major

comment:2 scribu3 years ago

Is there a way to invalidate the entire 'timeinfo' group?

comment:3 follow-up: scribu3 years ago

A compromise would be to use a single cache key for all post types. That will still probably take care of the original problem.

comment:4 scribu3 years ago

  • Owner set to scribu
  • Status changed from new to accepted

comment:5 scribu3 years ago

Going to close as dup of #14922, to keep everything in one place.

comment:6 in reply to: ↑ 3 mdawaffe3 years ago

Replying to scribu:

Is there a way to invalidate the entire 'timeinfo' group?

No. Memcache (and most wp_cache implementations) cannot do this.

There's a way around this, but it's tricky. You keep track of an incrementor, $i, in the cache and then do cache operations on the group "timeinfo-$i". To "invalidate" the group, you increment $i using wp_cache_incr().

Replying to scribu:

A compromise would be to use a single cache key for all post types. That will still probably take care of the original problem.

That would work.

comment:8 ryan3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.