The concept of CACHE_ANYTHING is primarily used in core where we want to cache something somewhere even if the "main" cache has not been configured by the local site administrator (e.g. is still CACHE_NONE, per the default settings.) Typically this means that something is sufficiently expensive to compute that we don't mind using the Database to store it - since all cache groups default to CACHE_NONE and ObjectCache::newAnything falls back to CACHE_DB.
This status quo is based on the very old assumption that most keys are "as expensive or less expensive" to generate than a database query, which is why the default is CACHE_NONE, and not CACHE_DB.
I'd like to challenge this assumption and instead recommend that anything sufficiently cheap to generate that doesn't want to be stored in the database, should probably use APC instead and fallback to nothing.
Another way to avoid being stored in the database is by using the new getQoS() interface to determine whether the cache backend is SQL or not. This is already in use in various places and represents a more scalable approach.
Additionally, the problem with CACHE_ANYTHING is that it predated WANObjectCache, which means it isn't multi-DC aware.
Highly expensive, or non-volatile | More expensive, volatile | Expensive, volatile | Cheap, volatile | |
---|---|---|---|---|
Current | MainStash (default: DB) | CACHE_ANYTHING | WAN cache (default: None, typically Memcached) | Local server (APC if available, fallback: None) |
Proposed | MainStash (default: DB) | ……… | WAN cache (default: TBD, typically Memcached) | Local server (APC if available, fallback: None) |
Action items:
- Decide what to do with getLocalServerInstance( CACHE_ANYTHING ) idiom. Once "Main cache" defaults to CACHE_DB, we could remove this option in favour of an option that takes one of ObjectCache::SRV_OR_NONE (default), ObjectCache::SRV_OR_PROC (fallback=Hash) or ObjectCache::SRV_OR_CLUSTER (fallback=Main), which is more explicit about which way the use case leans.
- Deprecate the concept of CACHE_ANYTHING. Convert uses to MainStash, WANObjectCache, or local server cache.
- Decide whether it would be beneficial for most things that use WAN cache to use a DB-backed store, or whether having no cache is still generally a more performant default than using a database as the cash.
- Option A) Make DB the default WAN cache, and move things that would no longer make sense for WAN cache (knowing it can be DB-based) down to the LocalServer cache. Downside: This would make then no longer cached as well for WMF.
- Option B) Keep NONE as default WAN cache, and move things that don't want to ever use "none" for and make sense to fallback to a DB for, to the MainStash (such as rate limiting). Downside: They would move from Memcached to MainStash at WMF. And they would no longer have all the WAN-optimisations for stampede control and tombstones etc.
- Remove ObjectCache::newAnything(), CACHE_ANYTHING etc.
Uses of CACHE_ANYTHING
- mediawiki-core
- Skin (getCachedNotice) – use WANObjectCache – https://gerrit.wikimedia.org/r/362608
- SpecialVersion (getCreditsForExtension)
- JobQueue (dupCache param)
- CacheHelper (for "chunks")
- ServiceWiring (for SiteStore if !HHVM) – use APC always, maybe with anything as fallback
- EventLogging
- RemoteSchema (default cache)
- CentralAuth
- SpecialGlobalUserMerge (rate limiting) - use what core uses?
- SpecialCentralAutoLogin (if !HHVM) – use APC always, maybe with fallback?