Storing some value so that it can be used throughout the session

Hello

When user logs in successfully, I want access some user info only once and then store it in session variable so that it can be used on all pages in that app. How can I do this in frappe?

I have found in one post to store value in cache. Here is the link. post

But where to define this?

Also, how can we store value in session ?

I have the same requirement. But I wanted to use the information at Print Format. Basically, I wanted to set some variables on the session to just call the value on printformat. I did want to generate it everytime I create the print format. Hence what I wanted to do.

I had my code on boot.py (boot_session) reference to have run on login. Executed the set on cache. But when called on Print Format, the frappe.cache() has a None value. So gets giving errors.

If anyone has a work around on this, mind sharing, that would be helpful.

1 Like

I don’t know if this can help you. I am doing as follows. in boot.py,

def boot_session(bootinfo):
bootinfo.user_depts = frappe.db.sql_list(""β€œselect … β€œβ€β€, frappe.session.user)
return bootinfo

def getBootInfo():
bootinfo = frappe._dict()
return boot_session(bootinfo)

then wherever I want to use this, I make a call to getBootInfo() as follow:

boot = getBootInfo()
depts = β€œβ€™,’”.join(boot.user_depts)