Add data to a user session

Hello everyone,

I’m trying to add some data into data dict in a session. Why?

I want that my app use a specific value selected by the user in all the pages without passing it through get method. the reason for this is i have some pages that show information based in the value selected by the user.

Example: you have two kids and when you select one of them, in all the app the results are related with the kid selected. passing this value in every page it is not a good idea.

something like frappe.session.kid_selected .

Any idea to do what i want even if it is in another way.

Add it to cache.

frappe.cache().set_value(key, value)
value = frappe.cache().get_value(key)

# or pass a generator method

def generator_func():
  # do something
  return value

value = frappe.cache().get_value(key, generator_func)


Thanks for your answer. That’s similar what i need but only for the user in the page. Another user have another kids.

Your key should have user as a part of it.

Thanks now it’s working.

@rmehta , @geekroot

What do you means by Add it to cache? Where should i add the code ? in python? which python file ya? Can you give me a hint please? Thank you very much, your help is highly appreciated.

Yes, the code above is python code. The file you need to use to set the value is the file related with the page/doctype where the user will select the value to be cached.

Can you please give me very simple example that u implemented? Tyvm

Sorry but that was two years ago and i have no access to the project anymore.

@geekroot @rmehta can you help me by saying that how can i unset session that i setted by above method

@shahid_ecit I think this can help you: frappe.cache().delete_key(“key_name”)

1 Like

@geekroot thanks for replay it is working also thanks very much

@shahid_ecit thanks you for being part of the community :v:

1 Like