ObjectCache is responsible for creating and fetching various cache instances (backends) for MediaWiki making use of BagOStuff which is the mechanism to do caching in the software's ecosystem.
Overtime, ObjectCache has been built to create and configure various types of caching backend such as: RESTBagOStuff, SqlBagOStuff and many more and the class itself was beginning to handle returning different types of BagOStuff with respect to the parameters supplied. This was an indication that we would someday need a factory to extract such logic into it and leave ObjectCache with the bare minimum. So logic for creating the different types of BOS instances will be handled by a separate service on its own - a name of such service an be ObjectCacheFactory.
As of today, there are 2 ways for ObjectCache to get a cache instance:
(1) Directly via ObjectCache::getInstance() plus some config setting like $wgObjectCaches['...'] = [ ... ] and this bypasses service wiring and creates a cache instance directly.
One of such use cases for this is creating a DB connection (on installing MW or otherwise), we don't necessarily need a services container to have been ready by this time so we need a way to still make use of local caches.
Another use case is when we're doing extension registration, the ExtensionRegistry would want to make use of local caches and at this time, the MW services container may not have been initialized meaning getting one will have to do so without service wiring.
(2) Fetching or creating cache through service wiring. This is something we can achieve when the services container is available and we're using it already in a lot of places already. A use case is an extension like ConfirmedEdit which makes use of the MicroStash to save captcha tokens. By this time, the extension has already been loaded and the MW services container is already initialized so using a service to access the cache for get/set is completely fine.
Problem
The problem now arrises when both approaches above gets used interchangeable. It works but it creates a lot of inconsistencies in our codebase and makes code unstable. We want to unify and make things consistent so that only when we need to bypass service wiring that we do otherwise we will have to go through service wiring as a lot of our code is already doing today.
The factory would need to support backward compatibility as there are cases whereby we try to mutate ObjectCache::$instances directly since this member is public. Worse of all, even some tests try to do this too.