5 Replies Latest reply on Sep 24, 2008 5:09 AM by gregtk

    s:graphicImage browser cache problem

    gregtk

      I use s:graphicImage to show images of chapters. But internet browser doesn't  cache it and everytime I click on link which on the page with chapters, browser download all images again.


      I think that server must send 304 Not Modified, but how to do that?


      this is example of how I insert my images to page


      <div class="left_image">
            <s:graphicImage value="#{chapterView.loadImage(chap)}" fileName="chapter-#{chap.id}">
                 <s:transformImageSize width="223" height="126"/>
            </s:graphicImage>
      </div>
      



      Somebody help me to resolve this problem, please

        • 1. Re: s:graphicImage browser cache problem
          • 2. Re: s:graphicImage browser cache problem
            gregtk

            Thank you for your response :) Can I help to add this feature? Now I just write temporary solution with servlet which add to response data header next information.


                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(new Date());
                    calendar.add(Calendar.YEAR, 1);
                    response.setDateHeader("Expires", calendar.getTimeInMillis());
            


            I think if I add this lines to render of <s:graphicsImage> tag and bind with attribute like <s:graphicsImage cache=true> it helps to resolve cache problem. What do you think about it?
                   


            • 3. Re: s:graphicImage browser cache problem

              You have to use the filename tag for this to work at all (otherwise the image will get a random generated namne).


              Cache=true is not really good since if you change transformImageSize (or add/modify any other transformes) the browser will not update the image, given that you have set the expires date to the future. Also, if you use the image in another place, with other transforms, you will have the same problem...

              • 4. Re: s:graphicImage browser cache problem

                My approach works like this:


                <s:graphicImage cachable="true" cacheKey="#{expression that is unique}" dirty="#{expression that determines if the original image has changed}"/>



                Then the code, if cachable=true and pojocache is on will put the transformed image in the cache, if not already there with given key. If dirty evaluates to true, the cached image is re-cached. The key is made up so that different transforms don't conflict. The key can also be used to remove the image frim cache progamatically. Typical key might be fileName-height-width

                • 5. Re: s:graphicImage browser cache problem
                  gregtk

                  Yeah! that's very good idea. I think that's more intelligent than mine.