OllieJones / sqlite-object-cache

A WordPress persistent object cache for the rest of us.
GNU General Public License v2.0
25 stars 5 forks source link

Implement `WP_CACHE_KEY_SALT` const #16

Closed spacedmonkey closed 1 year ago

spacedmonkey commented 1 year ago

The WP_CACHE_KEY_SALT const is used to cache invalidate. Core uses and many popular plugins use it as well. This plugin should use it as well.

OllieJones commented 1 year ago

Each site (or network containing multiple sites) creates its own cache .sqlite file. The primary purpose of this "salt" is to tag entries from different sites/networks that share a single cache. Agreed that it should be there to meet user expectations, but it is, strictly speaking, not necessary.

If a future version of this allows the sharing of .sqlite files by multiple sites/networks, this will become useful.

spacedmonkey commented 1 year ago

There are a couple of ways to implement this.

  1. Add the salt to the key generation. See
  2. Prefix the file name with salt.

WP_CACHE_KEY_SALT is used by all of the popular object caching drop-ins. Even wp-redis, which this plugin is based on.

OllieJones commented 1 year ago

We append the salt to the cache's SQLite filename. (There's nothing to be gained by lengthening the cache item names, because each .sqlite file is used for only one install anyway.