Automattic / wp-cache-memcached

Memcached Object Cache for WordPress
6 stars 0 forks source link

Handle large memcached keys more gracefully #2

Closed WPprodigy closed 1 year ago

WPprodigy commented 1 year ago

The Memcache php extension automatically truncates keys over 250 length. This isn't super ideal, since the part being truncated could have been the bit that varied between keys. As in: {$some_large_key_string} + {$post_id}.

The Memcached php extension doesn't truncate and will just fail any operation instead. I like this approach more, but for compatibility we need to do something as there are plugins using unbounded strings such as parts of a page url as apart of the key - so they do extend past the 250 limit Memcached server limit.

Rather than implementing app-side truncation, this approach instead will hash the string when it's over the limit and append it to the first 200 chars before sending to the servers. This happens very late in the process, so no user-land bits are affected or will even know about this happening. The benefit for keeping the first 200 chars is just in case some exploration is being done trying to debug issues starting at the server side. It should be more than enough to track down the source of the key creations. I've added a :truncated: string as well to help signify when this behavior has taken place. A sort of clue for any future debuggers.