Page 1 of 2
Cache / Avoid request to database for each page request
Posted: 22 Apr 2020, 09:26
by vished
Hi,
I like this template really much, but currently I have the problem the page load it not really fast due to the following reasons:
Left menu:
- I have on the left side in the calendar e.g. p:repeat to load the last 20 meetings from my database
Topbar:
- Load notifications
- Load messages
- Load image from loggedin user
This means, it´s for each page request also everytime a request against to the database, which slow down the whole application.
Can you give me a few ideas, how I can improve this to avoid to have always a request against the database?
- E.g. caching?
- 20 Meetings (left menu) will be loaded (request to database) only if the user open the second icon (calendar) ? -> how is this possible? I think this can be managed with the new event in the menu?
Any ideas?
Re: Cache / Avoid request to database for each page request
Posted: 06 Oct 2020, 12:17
by vished
any update regarding this?
Re: Cache / Avoid request to database for each page request
Posted: 10 Oct 2020, 03:14
by mert.sincan
Hi,
So sorry for the delayed response!
I think this can be managed with the new event in the menu?
- Yes, a new event can be added for this issue. We can implement this with you next week ??
Best Regards,
Re: Cache / Avoid request to database for each page request
Posted: 23 Mar 2021, 16:24
by vished
Did you implemented this?
Re: Cache / Avoid request to database for each page request
Posted: 03 May 2021, 15:14
by mert.sincan
Hi,
Sorry for the delayed response. Yes, I added tabChange and tabContentLoad events for this. You can use tabContentLoad event to load dynamic content.
Code: Select all
<h:form>
<pm:tabMenu id="tabMenu">
<p:ajax event="tabContentLoad" listener="#{testView.loadContent}" update="tab1:tab1_menu" />
<pm:tab id="tab1" icon="pi pi-folder-open" title="FEATURES">
<pm:menu id="tab1_menu" model="#{tabView.model}" widgetVar="MorpheusMenuWidget">
</pm:tab>
</pm:tabMenu>
</h:form>
...
public void loadContent(TabContentLoadEvent e) {
Tab tab = e.getTab();
if (tab.getTabIndex() == 0) {
// add items to model
}
}
Best Regards,
Re: Cache / Avoid request to database for each page request
Posted: 06 May 2021, 10:07
by rider
That´s great... Mabe it will fix my issue with p:cache...
Can you give an example how the backend bean should be looing like to create the model like:
Code: Select all
<pm:menu id="tab1_menu" model="#{tabView.model}"
What is "model" ?
Re: Cache / Avoid request to database for each page request
Posted: 06 May 2021, 10:18
by mert.sincan
Re: Cache / Avoid request to database for each page request
Posted: 06 May 2021, 11:09
by rider
I´ve tried that:
Code: Select all
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.morpheus.component.Menu;
@ViewScoped
@Named
public class LeftMenuController implements Serializable {
private static final long serialVersionUID = 2815796004558360299L;
private final Logger LOGGER = LoggerFactory.getLogger(LeftMenuController.class);
private Menu model = new Menu();
@PostConstruct
public void init() {
DefaultMenuItem item = DefaultMenuItem.builder()
.value("External")
.url("http://www.primefaces.org")
.icon("pi pi-home")
.build();
model.getElements().add(item);
}
Code: Select all
<pm:tab icon="fa fa fa-tachometer"
title="TEST">
<pm:menu model="#{leftMenuController.model}" />
</pm:tab>
But it´s not working....
I short example would be great...
Also can I ?
a) Create the whole <pm:tabMenu based on backend bean? ( I will create pm:tab <pm:menu / p:submenu / p:menuitem from backend?
b) create only the menu items in a <pm:tab?
Re: Cache / Avoid request to database for each page request
Posted: 06 May 2021, 11:49
by rider
Ok, I´ve created the menu, this works...
Code: Select all
private MenuModel model = new DefaultMenuModel();
@PostConstruct
public void init() {
DefaultMenuItem item = DefaultMenuItem.builder()
.value("External")
.url("http://www.primefaces.org")
.icon("pi pi-home")
.build();
model.getElements().add(item);
DefaultSeparator defaultSeparator = new DefaultSeparator();
defaultSeparator.setStyleClass("layout-submenu-title");
model.getElements().add(defaultSeparator);
}
But it seems for: pm:tabMenu I cannot create a
model="#{myController.model}". Is this right?
If yes, would it be possible to add this also?
Re: Cache / Avoid request to database for each page request
Posted: 07 May 2021, 08:17
by mert.sincan
Hi,
Yes, right! We'll work on it and get back to you.
Best Regards,