IAmYourFaja
IAmYourFaja

Reputation: 56912

Singleton or Object Caching?

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

Answers (1)

Bozho
Bozho

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

Related Questions