WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 22 months ago

Last modified 22 months ago

#4476 closed enhancement (wontfix)

Delete Cache by Group

Reported by: filosofo Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.2
Component: Cache API Keywords: has-patch close
Focuses: Cc:

Description

Currently, you have to specify the id of the cached item in order to delete it via wp_cache_delete, or you have to flush the entire cache via wp_cache_flush.

Instead, it would be helpful if one were able to delete an entire group without having to flush all of the cache.

For example, term-related plugins could expect their particular caches to be deleted whenever changes to any terms were made, instead of having to use callbacks for every term-related action.

Attachments (1)

cache.php.diff (1.1 KB) - added by filosofo 7 years ago.

Download all attachments as: .zip

Change History (12)

filosofo7 years ago

comment:1 filosofo7 years ago

  • Keywords has-patch added

comment:2 ryan7 years ago

  • Milestone changed from 2.3 to 2.4 (next)

comment:3 ryan6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Cache has been gutted, so this is no longer relevant.

comment:4 Nazgul6 years ago

  • Milestone 2.5 deleted

comment:5 sc0ttkclark22 months ago

  • Cc lol@… added
  • Keywords dev-feedback added
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Version set to 2.2

Looks like the reason this was closed is no longer the case. What's the plan here? I want to delete all items for a specific group.

For now, I'll just work with the object itself, but there's a definite need for a function like wp_cache_delete_group or the patch as attached.

comment:6 SergeyBiryukov22 months ago

  • Component changed from Administration to Cache
  • Keywords cache wp_cache_delete removed
  • Milestone set to Awaiting Review

comment:7 scribu22 months ago

The reason this is not part of the API is that most persistent caching backend such as memcache don't support deleting an entire group.

What's done instead is increment the group prefix and let memcache's garbage collector remove the items from the old group, which are never accessed anymore.

comment:8 scribu22 months ago

  • Keywords close added; dev-feedback removed

comment:9 sc0ttkclark22 months ago

  • Resolution set to wontfix
  • Status changed from reopened to closed

Okay, sorry for my n00bness as I'm diving deeper into WP caching than ever before, but how would I increment the group prefix? Feel free to reply with a *slap*

comment:10 scribu22 months ago

Actually, you don't change the prefix of the group, but add a prefix to each individual key:

$ns_key = wp_cache_get( 'foo_namespace_key' );

// if not set, initialize it
if ( $ns_key === false )
  wp_cache_set( 'foo_namespace_key', 1 );

$my_key = "foo_".$ns_key."_12345";
$my_value = wp_cache_get( $my_key, 'some_group' );

To clear the namespace do:

wp_cache_incr( 'foo_namespace_key' );

Source: https://groups.google.com/forum/?fromgroups#!topic/memcached/Izov0cFjBXI

comment:11 scribu22 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.