The new wildcard flushing mechanism is beyond cryptic. Code of this complexity shouldn't exist without thorough documentation. Yet we have it here, and not even a basic high level explanation of what is supposed to be happening is provided.

Comments

bleen’s picture

subscribing

jeremy’s picture

The logic was just optimized, and I added comments inline in the process. It should be easier to follow along with the logic now.

We track wildcard flushes by incrementing a simple counter named for the table and cid being flushed, and update a global object tracking for each table the lengths of each cid that has been wildcard flushed. As memcache is a hashtable, we can't efficiently find all matching items.

Then, at get time we check for matching wildcard flushes. Say we're doing a cache_get on 'foo' from the 'bar' table. If someone flushed 'f*', 'fo*', or 'foo*' since our item was cached, then we know our cached object is stale. We check the global object to determine which cid lengths we even need to bother looking up, skipping those that couldn't possible have been flushed, and doing a getMulti on the rest.

We also check for matching wildcard flushes when storing an item. We simply take a sum total of all matching wildcard flushes, and store that within the cache object. This is how we know the difference between old wildcard flushes and flushes that have happened since we stored out item.

catch’s picture

Subscribing, I've spent a fair bit of time with this now. Jeremy's explanation is good.

Mark Theunissen’s picture

Subscribing.

catch’s picture

I started a handbook section for memcache to make the main project page a bit tidier - http://drupal.org/node/1131458

That would be a good place to add this.

Note we are still tweaking this a bit, so there might be some slight changes to the implementation.

Also I am starting a push to remove wildcard prefix clears in Drupal 8 and replace it with a 'tags' system at #636454: Cache tag support - the current wildcard logic should adapt really well to tags, but that's even more of a reason to document it.

japerry’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.