I'm storing logged in User object in Play cache (using play.cache.Cache) like this.
User user = userRepo.findUserFromDB(id);
String uuid = java.util.UUID.randomUUID().toString();
Cache.set(uuid, user);
session("uuid", uuid);
I want to use this object in every view I render (to display information about logged in user in the footer template). One way would be to pass this object to views from every controller as an argument, but it's definitely not the way of doing it.
String uuid = session("uuid")
User user = Cache.get(uuid);
return ok(
dashboard.render(user, other_params)
);
What would be the most elegant way of doing it to maximize code re-use?