Quantcast
Channel: Is utilizing a singleton for a cache an antipattern? - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 8

Answer by supercat for Is utilizing a singleton for a cache an antipattern?

$
0
0

While there are many situations where using a singleton cache may be more convenient than having to maintain and pass around a caching context, many situations may arise where such designs end up creating difficulties. If the purpose of a cache is to store things that are by nature genuinely immutable (e.g. numbers and their cube roots), and the cache does not allow outside observation of its state, then having the cache be a singleton would be unlikely to cause any trouble. If, however, a cache is meant to be attached to some mutable entity and track its state, then having the cache be a singleton will effectively compel the observed object to be a singleton as well.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images