Reputation: 56912
Are there ever any performance (speed & memory) benefits to using a properly-implemented singleton object vs. caching a single object and fetching it out of cache as it is needed?
Upvotes: 3
Views: 2955
Reputation: 597114
There isn't any difference, not only performance, but also logical. A singleton "caches" its instance in its own static field, so it's logically a cache as well.
And your cache should have a singleton-preserving-logic, which most caches don't have.
Distributed scenarios are a different story, but in that case you should have the data cached, rather than an instance.
Upvotes: 5