Enabling browser caching via java

Posted by Franz See on Stack Overflow See other posts from Stack Overflow or by Franz See
Published on 2009-07-07T10:21:13Z Indexed on 2010/04/27 21:43 UTC
Read the original article Hit count: 387

Good day,

I am using CacheFilter to filter a certain path to my server (which outputs an image stream to the response stream). And I've configured it in my web.xml as follows:

<filter>
    <filter-name>imagesCache</filter-name>
    <filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>public</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>2592000</param-value>
    </init-param>
</filter>

...
<filter-mapping>
    <filter-name>imagesCache</filter-name>
    <url-pattern>/my/path/*</url-pattern>
</filter-mapping>

Using my firefox, if I access my url via the address bar, it hits the server the first time but uses the cache during succeeding calls. However, if the url is inside my page ( i.e. <img src="..."/> ), it seems to hit the server all the time.

[EDIT] After a few more testing, accessing my image via the address bar does not work all the time. But caching does seem to work more often with it than . As to whether it really, I am not sure.

Additional Info: my path is something like /my/path?then=some&query=strings. Notice that it doesn't have an extension (i.e. gif, png, jpeg ) but it's mimetype is set properly ( image/gif, image/png, image/jpeg ). I am not sure if the lack of extension or the presence of the query strings have any impact. (Also, another note. though my url have query strings, I am using the same uri + query string over and over again with my tests).

Any ideas why?

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about cache-control