开发者

Singleton or Object Caching?

开发者 https://www.devze.com 2023-04-04 09:46 出处:网络
Are ther开发者_StackOverflowe 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 need

Are ther开发者_StackOverflowe 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消