Christian,

In Turbine 3.0 Code there is a method that is called setCacheHeaders in the
Turbine.java file. Useful, however it has a bug where it adds milliseconds
to seconds. So here is a fixed method that you could add somewhere and call
depending on what you wanted to cache.

    /**
     * This method sets the required expiration headers in the response
     * for a given RunData object.  This method attempts to set all
     * relevant headers, both for HTTP 1.0 and HTTP 1.1.
     *
     * @param data The RunData object we are setting cache information for.
     * @param expiry The number of seconds until the document should expire,
     * <code>0</code> indicating immediate expiration (i.e. no caching).
     */
    public static void setCacheHeaders(RunData data, int expiry)
    {
        if ( expiry == 0 )
        {
            data.getResponse().setHeader("Pragma", "no-cache");
            data.getResponse().setHeader("Cache-Control", "no-cache");
            data.getResponse().setHeader(
                    "Expires", HttpUtils.formatHttpDate(new Date()));
        }
        else
        {
            /*
             * Convert to long to handle large milliseconds
             */
            long lExpiry = new Integer(expiry).longValue();
            lExpiry = lExpiry * 1000;
            Date expiryDate = new Date( System.currentTimeMillis() +
lExpiry );
            data.getResponse()
                .setHeader("Expires", HttpUtils.formatHttpDate(expiryDate));
data.getResponse().setHeader("Pragma", "max-age=" + expiry);
            data.getResponse().setHeader("Cache-Control", "max-age=" +
expiry);
        }
    }

Alternativly this can be written to accept a long in the first place for
expiry I guess.

-Peter


----- Original Message -----
From: "Heiko Braun" <[EMAIL PROTECTED]>
To: "Turbine Users List" <[EMAIL PROTECTED]>
Sent: Friday, February 22, 2002 6:29 AM
Subject: Re: How to avoid browser cache


> take a look here:
>
>
http://www.mail-archive.com/turbine-user%40jakarta.apache.org/msg02623.html
>
> /heiko
>
> Am Fre, 2002-02-22 um 13.13 schrieb Christian Asmussen:
> > I've had a problem with some browsers like opera and IE for the example
> > app created by turbine 2.1.  I clicked on the "Home" link of the menu
and
> > was not logged in, so the Login screen apears.  After login in, I tryied
> > the same link again, but the browser had cached a copy of login, so I
was
> > redirected to the login screen again.  Of course, by clicking on the
> > reload button the problem was solved.  The thing is a regular user won't
> > do that.  How can I avoid these caches?  Should I set an expires now for
> > every page?
> >
> > --
> > "If we did all the things we are capable of,
> > we would literally astound ourselves"
> >  - Thomas Edison
> >
> >
> > --
> > To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
> >
> --
>  .-
>
>  Heiko Braun <[EMAIL PROTECTED]>
>  Software Entwicklung
>
>  Fon: 0172 / 871 95 20
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to