I am currently building a web application built on Flask Framework with around 10 user accounts in the future when the application has been finished.
There is a Class with heavy module (Compute-intensive), built and used in this application, served as one of the frequently used key features, and I have run into some issues and am seeking for some solutions (let's named it as Class A
in file a.py
)
Originally, I imported the Class A
directly into one of the view
file, and created a route
function for it, that once an user clicks the button which invokes this route
, the route
function will then create an instance of Class A
, and this instance runs based on received data (like Json). But I found the system can be slow down as the instance of Class A
has to be created every single time when the user uses the feature frequently, (also there can be 10 users), and Class A
is too heavy to be created again and again.
Therefore I am thinking is there anyway that I can create the instance of Class A
for only one time (e.g., the time that the Flask application starts), and each logged in user can access this instance rather than create it over and over again?
Thanks in advance