Question

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

Was it helpful?

Solution

You want to especially look for any Cache-Control header in your request. If a request says something like Cache-Control: no-cache or Cache-Control: max-age=0, then caches can't serve up a cached copy. Or if the response has an Expires header that's too close in time, then it can't be cached for long.

The complete list of headers and explanations is in the HTTP 1.1 specification. See Caching in HTTP (13) and Header Field Definitions (14)

The Firebug plug-in is one good way to check request and response headers using Firefox.

Also watch out how you're using Firefox. Hitting the refresh button is equivalent to saying Cache-Control: no-cache -- it says you want the freshest copy possible, which takes you all the way back to your origin web server.

OTHER TIPS

I would investigate the HTTP request being sent - particularly the HTTP headers being sent for that image request. You can use a Firefox plugin, and/or check the headers at the servlet end (in the HttpServletRequest object)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top