Create navigation static menu and store it

Hi All,

I am working on an app where the navigation menu needs to change based on the options enabled for the user. This fires db queries to check the user privileges every time menu loads.

I want to be able to generate the menu at login and store it as static html for the duration of the session so that db queries are not fired at every page change. What would be the best approach for:

  1. generating the static html by computing the result of a dynamic template (includes if conditions for rendering the menu options)

  2. best approach to store it for the duration of the session and use it in navigation template or view.

Thanks in advance.

Use cache to save (for min/hours) menu type based on your user status.
Then take it from cache, e.g. Cachex.get(:my_cache, "user_#{current_user.id}_status_#{user_status}")
Don’t forget to delete/update cache when the user status has changed.

1 Like

Use ETS if its a single machine, use the user id as key

table = :ets.new(:menu, [:set, :protected])

:ets.insert(table, {"user3", value-here})

Write session login around it