You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Christian Asmussen <kr...@kriconet.com.br> on 2002/02/22 14:13:33 UTC

How to avoid browser cache

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Logging out is writing over the password

Posted by David Sean Taylor <da...@bluesunrise.com>.
When I logout, Turbine overwrites the user password.
(This is a problem since, in this particular app, the User Management is
done with an app external to Turbine)
Looking at the code executed in logout (DBUserManager):

    public void store(User user)
        throws UnknownEntityException, DataBackendException
    {
        if(!accountExists(user))
        {
            throw new UnknownEntityException("The account '" + 
                user.getUserName() + "' does not exist");
        }
        Criteria criteria = TurbineUserPeer.buildCriteria(user);
<===========================
        try
        {
            TurbineUserPeer.doUpdate(criteria);
        }
        catch(Exception e)
        {
            throw new DataBackendException("Failed to save user object",
e);
        }
    }

It appears that Turbine will write over *all* fields, regardless of
whether they are dirty or not.
Is this the desired approach, or a bug?
Do Peers support automatic updating of only the columns that have been
modified.
If so, how do you construct a Criteria to update for only the dirty
columns?

Thanks,

David

> -----Original Message-----
> From: Peter Lynch [mailto:peterlynch@mindspring.com] 
> Sent: Friday, February 22, 2002 10:03 AM
> To: Turbine Users List
> Subject: Re: How to avoid browser cache
> 
> 
> 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" <he...@hlan.org>
> To: "Turbine Users List" <tu...@jakarta.apache.org>
> 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:
> <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> > >
> > --
> >  .-
> >
> >  Heiko Braun <he...@hlan.org>
> >  Software Entwicklung
> >
> >  Fon: 0172 / 871 95 20
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:turbine-user-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to avoid browser cache

Posted by Peter Lynch <pe...@mindspring.com>.
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" <he...@hlan.org>
To: "Turbine Users List" <tu...@jakarta.apache.org>
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:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
> --
>  .-
>
>  Heiko Braun <he...@hlan.org>
>  Software Entwicklung
>
>  Fon: 0172 / 871 95 20
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to avoid browser cache

Posted by Scott Eade <se...@backstagetech.com.au>.
Paul,

I started the thread and I do recall posting a concluding message perhaps as
much as a couple of weeks later.

After believing I had struck upon the perfect set of headers to set:

  data.getResponse().setHeader("Cache-Control", "no-cache"); //HTTP 1.1
  data.getResponse().setHeader("Pragma", "no-cache"); //HTTP 1.0
  data.getResponse().setDateHeader("Expires", 0); //prevents caching at the
proxy server

... and the best way to do it:

  use a pull tool method to execute the above statements in my default
layout.

... I discovered that my client site was still experiencing problems where
old data was being displayed.

As a result I concluded that the extension to TemplateLink was the only
solution that would guarantee a refresh every time.  The implementation I
settled upon follows.  The nocacheid path info is added in getURI() and
toString() so that it works for setAction() as well as setPage().


import java.util.Date;
import org.apache.turbine.util.template.*;

/**
 * Title:        TemplateLinkEx<p>
 * Description:  Extension to TurbineLink that provides for unique URLs to
 * force caches to retrieve the page every time.  This is implemented in a
 * very bad way, but then TemplateLink itself is pretty shocking in that it
 * breaks the toString() contract by altering the value of the object.<p>
 */
public class TemplateLinkEx extends TemplateLink
{

    private static final String NOCACHE = "nocacheid";

    public String getURI()
    {
        super.addPathInfo(NOCACHE, new java.util.Date().getTime());
        String result = super.getURI();
        super.removePathInfo(NOCACHE);
        return result;
    }

    public String toString()
    {
        super.addPathInfo(NOCACHE, new java.util.Date().getTime());
        return super.toString();
    }

I still set the headers so that I don't fill well behaved caches with pages
that will never be used again.

HTH,

Scott


> From: Paul Szego <pa...@nebulon.com>
> 
> Hi,
> 
> I've read through this thread twice now, and although there's a lot of
> discussion there doesn't seem to be any conclusion.
> 
> Does anyone *know* how to do this, or is it a case of trying every
> approach listed there and see what works?
> 
> Regards, PaulS.
> 
> 
> Heiko Braun wrote:
>> 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:
>>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <ma...@jakarta.apache.org>
>>> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to avoid browser cache

Posted by Paul Szego <pa...@nebulon.com>.
Hi,

I've read through this thread twice now, and although there's a lot of 
discussion there doesn't seem to be any conclusion.

Does anyone *know* how to do this, or is it a case of trying every 
approach listed there and see what works?

Regards, PaulS.


Heiko Braun wrote:
> 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:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to avoid browser cache

Posted by Heiko Braun <he...@hlan.org>.
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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
-- 
 .-
 
 Heiko Braun <he...@hlan.org>
 Software Entwicklung

 Fon: 0172 / 871 95 20


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>