Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Caching a default instance to avoid initializing it every time (with Moo)

by Anonymous Monk
on Feb 08, 2018 at 18:42 UTC ( #1208737=note: print w/replies, xml ) Need Help??


in reply to Caching a default instance to avoid initializing it every time (with Moo)

This is a Singleton pattern, and that is how you should implement it. For instance, let there be a sub instance which either returns a cached copy or creates a new instance and caches it. Don't try to do this in a constructor or a wrapper around it you will confuse other people, at best. Give them what they are conditioned to expect to see. You also need to be very sure that you are storing the cached instance in a persistent global variable as you think you are.
  • Comment on Re: Caching a default instance to avoid initializing it every time (with Moo)

Replies are listed 'Best First'.
Re^2: Caching a default instance to avoid initializing it every time (with Moo)
by Your Mother (Bishop) on Feb 08, 2018 at 19:34 UTC
    Give them what they are conditioned to expect to see.

    Throwing a colander of words spaghetti at the wall and managing to have a piece stick is perhaps a valid approach to problem solving but so is doing blockchain in pencil and paper.

    You also need to be very sure that you are storing the cached instance in a persistent global variable as you think you are.

    Where is your example code to test this stern advice? If it was worth saying, it's worth showing.

    It is insulting that, again, there were three working, technical answers presented before your reply and you still felt the need to chime in, adding nothing. Then again, maybe you can't read the code in the three examples so you might not have realized the question was trebly answered already.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208737]
help
Chatterbox?
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-05-27 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?