cache clear issue in gwt

1,370 views
Skip to first unread message

Bhumika Thaker

unread,
Mar 20, 2015, 5:50:12 AM3/20/15
to google-we...@googlegroups.com

Hi,

I have deployed new version of my application on production server. 
It does not allow user to login and throw below error in my console server.

09:24:20,106 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (http--0.0.0.0-80-33)
 loginrpc: ERROR: The serialization policy file '/v4workflow/FB64C6F0204DFD63FB92E5485E94A4E0.gwt.rpc' was not found; 
did you forget to include it in this deployment?
09:24:20,106 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] 
(http--0.0.0.0-80-33) loginrpc: WARNING: Failed to get the SerializationPolicy 'FB64C6F0204DFD63FB92E5485E94A4E0'
 for module  a legacy, 1.3.3 compatible, serialization policy will be used.
you may experience SerializationExceptions as a result.

It's cache issue. it works fine. because after clearing cache in my browser
To solve this issue, If I add cache clear header in index.html, 
it will add cost to load js every time at client side and give performance issue.

I got so anwser from Thomas Broyer, I can't understand some portion like
servlet.getServletContext().getResourceAsStream. You can customize this by overriding doGetSerializationPolicy (as said in the JavaDoc).
The file name (resource URL) is built from the request's path and X-GWT-Permutation request 

Refer link:

do you know how to resolve cache clear issue in gwt?

Thanks,
Bhumika Thaker

Jens

unread,
Mar 20, 2015, 6:04:31 AM3/20/15
to google-we...@googlegroups.com
If you apply the correct caching headers there is only minimal overhead on each request because the browser first checks if a new version on the server is available and only if it is available it will download the new version. Otherwise it will continue to use the already cached version.

A lot of people use https://github.com/realityforge/gwt-cache-filter to apply caching headers to their gwt apps.

-- J.

Bhumika Thaker

unread,
Mar 20, 2015, 6:58:13 AM3/20/15
to google-we...@googlegroups.com
Hi,

Thanks for reply.

Let me implement it.
I have used local storage "Storage.getLocalStorageIfSupported()" to store certificate private key.
is value of local storage clear when cache clear?

Thanks,
Bhumika

Bhumika Thaker

unread,
Mar 20, 2015, 10:06:01 AM3/20/15
to google-we...@googlegroups.com
Hi Jens,

I have try this  -https://github.com/realityforge/gwt-cache-filter  with sample gwt example.
I have cross check with firebug. I found that each request is all time request new file instead of load from cache.
Have you add any extra setting for same?

Thanks,
Bhumika 

Bhumika Thaker

unread,
Mar 24, 2015, 3:02:30 AM3/24/15
to google-we...@googlegroups.com
I have implemented it successfully. It works fine. Below code needs to implement.

Added filter in web.xml
<filter> 
    <filter-name>gwtCacheControlFilter</filter-name>
    <filter-class>com.server.GWTCacheControlFilter</filter-class>
    <init-param>
       <param-name>private</param-name>
       <param-value>true</param-value>
   </init-param>
   <init-param>
       <param-name>expirationTime</param-name>
       <param-value>2592000</param-value>
   </init-param>
</filter>

GWTCacheControlFilter.java 

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

import com.samaxes.filter.util.CacheConfigParameter;
import com.samaxes.filter.util.Cacheability;
import com.samaxes.filter.util.HTTPCacheHeader;
/**
 * Code imported from cachefilter.jar
 * <br/><br/>
 */
public class GWTCacheControlFilter implements Filter {
private final static String[] STATIC_CONTENTS = { ".jpeg", ".jpg", ".gif",
".png", ".css", ".js", ".html" };
private Cacheability cacheability;
private boolean isStatic;
private long seconds;
private static final Logger LOGGER = Logger.getLogger(GWTCacheControlFilter.class);
public static final int YEAR_IN_MINUTES = 365 * 24 * 60 * 60;

public void destroy() {
}
public void init(FilterConfig filterConfig) throws ServletException {
this.cacheability = (Boolean.valueOf(filterConfig.getInitParameter(CacheConfigParameter.PRIVATE.getName())).booleanValue() ? Cacheability.PRIVATE : Cacheability.PUBLIC);
   this.isStatic = Boolean.valueOf(filterConfig.getInitParameter(CacheConfigParameter.STATIC.getName())).booleanValue();
   try{
     this.seconds = Long.valueOf(filterConfig.getInitParameter(CacheConfigParameter.EXPIRATION_TIME.getName())).longValue();
   } catch (NumberFormatException e) {
     throw new ServletException("The initialization parameter " + 
       CacheConfigParameter.EXPIRATION_TIME.getName() + " is missing for filter " + 
       filterConfig.getFilterName() + ".");
   }
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (requestURI.contains(".nocache.")) {
Date now = new Date();
httpResponse.setDateHeader("Date", now.getTime());
// one day old
httpResponse.setDateHeader("Expires", now.getTime() - 86400000L);
httpResponse.setHeader("Pragma", "no-cache");
httpResponse.setHeader("Cache-control",
"no-cache, no-store, max-age=0, must-revalidate");
}else if ( requestURI.contains( ".cache." ) ){
     // set expiry to back in the past (makes us a bad candidate for caching)
     final Calendar calendar = Calendar.getInstance();
     calendar.setTime( new Date() );
     calendar.add( Calendar.YEAR, 1 );
     httpResponse.setDateHeader( "Expires", calendar.getTime().getTime() );
     httpResponse.setHeader( "Cache-control", "max-age=" + YEAR_IN_MINUTES + ", public" );
     httpResponse.setHeader( "Pragma", "" );
   } else if (isStaticContentUri(requestURI)) {
StringBuilder cacheControl = new StringBuilder(this.cacheability.getValue()).append(", max-age=").append(this.seconds);
if (!this.isStatic) {
  cacheControl.append(", must-revalidate");
}
httpResponse.setHeader(HTTPCacheHeader.CACHE_CONTROL.getName(), cacheControl.toString());
httpResponse.setDateHeader(HTTPCacheHeader.EXPIRES.getName(), System.currentTimeMillis() + this.seconds * 1000L);
   if (httpResponse.containsHeader("Pragma")) {
     LOGGER.debug("found pragma header");
     httpResponse.setHeader(HTTPCacheHeader.PRAGMA.getName(), "");
   } else {
     LOGGER.debug("did not find pragma header");
   }
}
filterChain.doFilter(request, response);
}
private boolean isStaticContentUri(String uri) {
uri = uri.toLowerCase();
for (String contentType : STATIC_CONTENTS) {
if (uri.endsWith(contentType.toLowerCase()))
return true;
}
return false;
}
}

I have a query related to localstorage, like it's cache or cookie..It is part of cookie. 
Storage.getLocalStorageIfSupported() is part of cookie not cache. when I have clear cookie than it is clear.
Reply all
Reply to author
Forward
0 new messages