Фильтр кеширования лейаутов
Чтобы его включить нужно включить в пропертях portal-ext.properties:com.liferay.portal.servlet.filters.cache.CacheFilter=true
Дальше те портлеты которые не создают постоянно динамический лейаут должны у себя в liferay-portlet.xml:
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.0.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd"> <liferay-portlet-app> ... <portlet> ... <layout-cacheable>true</layout-cacheable> ... </portlet> ... </liferay-portlet-app>Таким образом мы не компилируем каждый раз лейаут, а возвращает кеш на него, но это вроде только для гестов.
Фильтр кеширования запросов
В этом случае это не лайфрейная фишка, а стандарта контейнера портлетов. Чему доказательство настраивание фичи в файле portlet.xml:<?xml version="1.0"?>
<portlet-app
version="2.0"
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
...
<filter>
<filter-name>GameInfoCacheFilter</filter-name>
<filter-class>com.playtech.portlet.games.gamesinfo.GameInfoCacheFilter</filter-class>
<lifecycle>RENDER_PHASE</lifecycle>
<lifecycle>RESOURCE_PHASE</lifecycle>
</filter>
<filter-mapping>
<filter-name>GameInfoCacheFilter</filter-name>
<portlet-name>games-info</portlet-name>
</filter-mapping>
</portlet-app>
Как видно мы указали фазы который на которые запросы к портелеты будут пропускаться через указанный фильтр.
Ну и реализуем фильр:
package com.playtech.portlet.games.gamesinfo;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.filter.FilterChain;
import javax.portlet.filter.FilterConfig;
import javax.portlet.filter.RenderFilter;
import javax.portlet.filter.ResourceFilter;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
public class GameInfoCacheFilter implements RenderFilter, ResourceFilter {
private Ehcache gameInfoCache;
@Override
public void doFilter(RenderRequest request, RenderResponse response, FilterChain filterChain) throws IOException, PortletException {
...
}
@Override
public void doFilter(ResourceRequest resourceRequest, ResourceResponse response, FilterChain filterChain) throws IOException, PortletException {
...
}
@Override
public void init(FilterConfig filterConfig) throws PortletException {
CacheManager cacheManager = ServicesHookContext.getBean("ehCacheManager");
gameInfoCache = cacheManager.getCache("gameInfoCache");
}
@Override
public void destroy() {
...
}
}
В данном случае показалась привязка к популярному инструменту для кеширования Ehcache.
Комментариев нет:
Отправить комментарий