InvisibleSoldiers wrote:it's a little weird don't you think so? I mean why would you do that.
I simply provided an example that came closer to your first snippet; simple retrieval of a key from a dictionary.
InvisibleSoldiers wrote:If anyone wants a cache he will dive into PlayerDictionary, and if not just Player(), you just created synonym of PlayerDictionary.
Both have very distinct use cases. PlayerDictionary is a container you have control over its content, while the other is an internal caching system. For example, if a plugin wants a Player instance from a hook he would do:
Syntax: Select all
player = make_object(Player, stack[0])
This is where the internal cache comes into play. Before, it would just instantiate a new Player every call, now it retrieves the instance from the internal cache and thus makes all future call to that function faster than it was.
InvisibleSoldiers wrote:And if i prefer PlayerDictionary, does it mean that i will have two cached dictionary at the same time?
It depend how you declare your dictionary. If you do not want to use the internal cache, or have the instances you created internally cached, you need to specify it explicitly to your factory class. E.g.
Syntax: Select all
players = PlayerDictionary(caching=False)
Which would make your instances private, and not cached into Player.cache whatsoever.