Hello group,I am looking for a way to build up and keep my domain model in memory during pyramid serves my application. This time I do not want to use a SQL database or ZODB as the persistence layer. I currently maintain an URL dispatch based pyramid app using ZODB - this is where my current pyramid experience is coming from.
Now I want to use pyramid to build an application to visualize data loaded from large CSV files on local harddisk. I use traversal to map URLs to folders and files. During application startup I create a basic resource tree while using several plain python model classes. Typical application usage should enlarge the resource tree by lazy loading child objects as requested by users. Lazy loading takes several seconds. This should happen only one time for every "resource" in the resource tree. My intention is to keep the main application object(a.k.a resource tree) in memory during several requests. Parsing CSV files during every request is way to slow. This actually happens.
As request by traversal based applications I do pass the root_factory to the Configurator. The pyramid glossary cleary notes: "The “root factory” of a Pyramid application is called on every request sent to the application.". This way the application restarts building the resource tree on every request.
def main(global_config, **settings):
raise ValueError('virginia requires a root')
fs = Filesystem(os.path.abspath(os.path.normpath(root)))
directory = Directory(fs, root)
application = Application(directory)
config = Configurator(root_factory=get_root, settings=settings)
I already tried passing a singleton to the root_factory. I currently do not use any caching/sessioning like beaker.
Any suggestions how to build up a resource tree at runtime that keeps alive during requests??? Thanks for your answers!