See https://gerrit.wikimedia.org/r/294959.
Instead of using HashBagOStuff as a central singleton, individual users of it should use their own instance and pass it down where needed. The class requires no parameters or injected fields, so usage should be pretty simple.
For the specific use case of process-caching things from memcaced, WANObjectCache introduced a built-in pcTTL option that should be used instead.
One the problems with the central singleton is that it can grow out of control, and there's no easy way to determine what its maxKeys should be given that usage is unknown.