You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to have a Singleton which functions as a cache for a method call.
I want the field file_content in my container be initialized one time by calling a given method (reader.read). From then on always that result should be returned instead of calling the method again.
I have added a working code example below.
Is there any better way?
Maybe it might be useful if it was rewritten as a new Provider?
read file
args: ('any arg',)
kwargs: {'any_kwarg': 'any_kwarg_value'}
first line: from pathlib import Path
first line: from pathlib import Path
first line: from pathlib import Path
The text was updated successfully, but these errors were encountered:
I simplified your code which you provided above and demonstrate new version of the code, as well as the output from the console, which shows that the instance of the Reader class is indeed a singleton.
I want to have a Singleton which functions as a cache for a method call.
I want the field
file_content
in my container be initialized one time by calling a given method (reader.read
). From then on always that result should be returned instead of calling the method again.I have added a working code example below.
Is there any better way?
Maybe it might be useful if it was rewritten as a new Provider?
Output:
The text was updated successfully, but these errors were encountered: