Programmatically Stopping Cache

Discussion in 'Programming' started by twalters84, Oct 14, 2007.

  1. #1
    Greetings,

    I was wondering if anybody knows of a way to programmatically stop client's browsers from caching certain website pages?

    I have a news section on my website that seems to cache really bad.

    Anybody have any suggestions?

    Sincerely,
    Travis Walters
     
    twalters84, Oct 14, 2007 IP
  2. liam1412

    liam1412 Active Member

    Messages:
    387
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    If you are dealing with similar things I stick this bit of code in any page you don't want caching

    session_cache_expire( 0 );
    session_cache_limiter( "nocache" );
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    PHP:
    It basically says - Do not cache this page, No really don't, Im not kidding don't cache it and so and so forth.

    Any other languages im not too sure.

    Thanks
     
    liam1412, Oct 14, 2007 IP
    twalters84 likes this.
  3. twalters84

    twalters84 Peon

    Messages:
    514
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey there,

    For coldfusion, I found something that says..

    <cfcache action="flush">

    For some reason, it does not appear to be working too well though.

    I thought there would be some sort of javaScript solution since the cache is happening client side.

    Thanks for the PHP solution though. It will come in handy if I ever make a PHP site. I really love coldfusion though :)

    Sincerely,
    Travis Walters
     
    twalters84, Oct 14, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The CF example looks like it is clearing the server cache rather than the client - you would need to see what renders as the way to do it is with header/ meta tags.

    Response.AddHeader("cache-control", "no-store, must-revalidate, private")
    Response.AddHeader("Pragma", "no-cache")
    Code (markup):
    is the ASP/ ASP.Net version but the other option is to add a historic absolute expiry date
     
    AstarothSolutions, Oct 15, 2007 IP
    twalters84 likes this.
  5. cristalron

    cristalron Peon

    Messages:
    19
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Maybe this works:
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    or
    <META HTTP-EQUIV="EXPIRES"
    CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
     
    cristalron, Oct 15, 2007 IP
    twalters84 likes this.