Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to bust website's cache serverside? It's showing the old version.

Posted on 2014-01-09
11
229 Views
Last Modified: 2014-10-22
Hello,

I have a wodpress site that I recently migrated from a dedicated server to cloud servers. It was still showing me the old version (new content wasn't appearing) on my computer so I cleared cache and that fixed it.

On my phone it still shows the old version that doesn't have the latest content. A few friends have also told me they see the old version, so I am guessing a lot of my old visitors see the same thing.

How can I solve this? I tried putting this in the header.php of the site on the old and new server:

<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0">

Open in new window


But it hasn't helped.

DNS records properly point to the new site.

How do I fix this cache issue?

Thank you!
0
Comment
Question by:it1000
  • 4
  • 4
11 Comments
 
LVL 12

Expert Comment

by:aindelicato
ID: 39768631
do you have any cache plugins installed like Super Cache?

See this site:
http://wp.tutsplus.com/tutorials/scaling-caching/wordpress-caching-plugins/



Disabling Browser Cache in HTML
With this code placed in the top of the head section you can turn off client side caching.
1
2
3
4
5
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

Disabling Server Side Cache in PHP
This little two liner code goes to the uppermost part of a PHP file.
1
2
3
4
<?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39768879
Those are good suggestions and i use them myself.  The trouble with all of those methods is that they don't take effect until the current cached items expire.  The server can not clear the browser cache.  It can only 'ask' that the page not be cached when it is finally loaded from the server.  

Note that the purpose of caching is to speed up web browsing.  If you set it up so that nothing is cached, you force the browser to go back to the server for everything which is slower.  In addition, preventing caching of the HTML does not stop caching of images and javascript.  I frequently change the name of the images or javascript in a new version of a page so that the page will fetch the new versions of images and javascript too.
0
 

Author Comment

by:it1000
ID: 39769434
Thank you for your replies. I just want to get over this hurdle then I will set things back to normal.

I tried putting that code in the headers of both the old and the new site, didn't help.

Also, this may give you a clue:

I logged into the old site, deleted the latest articles, and refreshed the site on my phone. If it was indeed pulling from the old site, then the latest articles should disappear since I deleted them. But they still do appear.

How can I basically make the site convince my phone's browser to refresh the content?

I also thought it might be DNS related so I check the domain ttl but it's 1 hour, so it can't be. I migrated the site days ago.

Thank you for your help with this pesky issue.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39769481
The cache that is giving you a problem is in your browser on your computer and phones.  Nothing you do on the server will have any effect until you are able to load a new page from the server and not from your cache.  This is a problem I run into all the time when I upload a new pages for a website.

You have to look up the method for forcing your browser to do a complete refresh from the server.  In IE and Firefox on the desktop, it would be Ctrl-F5.  I don't know what it would be on your phone.
0
 

Author Comment

by:it1000
ID: 39769890
I did CTRL-F5 and it didn't help.

Also, I deleted everything in /wp-content/cache

Even if CTRL-F5 worked, I cannot ask all my visitors to do CTRL-F5

The only thing that has worked so far is clearing my cache in Chrome. Sure, it solves the problem for me, but the real problem is my visitors.

There has to be a way, no?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39769970
No, no way.  The server can Not clear what is in the client's cache.  All it can do is ask it not to cache the page... when it finally gets a new copy.  

Even more to the point, the server can not do Anything to the client except respond to requests.  And the browser on the client will only ask for a new copy of the page when the cached copy expires or you tell it too.
0
 

Author Comment

by:it1000
ID: 39769998
Good point, I've been digging around and I think that making the browser believe all files have been recently modified will make it request new versions, which would effectively solve the problem.

How can I force Last-Modified in htaccess? Basically I want every request to tell the browser that the file in question has been modified today!

Any other ways? Can I change the last modified date for all files for my site, alternatively? If so how?

I think this should solve the problem.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39770128
Technically, the browser makes a 'conditional' GET request with "If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field."  http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html  The server response if the server sees no change in the file date is a "304 Not Modified".

Here is the RFC on caching: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13

Thru FTP or a script on the server you can change the date of the files.  While in theory that should work, I know from experience that it doesn't always work.  This is especially true of files that are loaded from the HTML file like images and javascript.  I have at times had to load an image or javascript directly in the browser and then do a Ctl-F5 refresh to get it to update.

This http://www.paulund.co.uk/set-expire-headers-in-htaccess appears to be a decent article on setting expiration times in '.htaccess'.

Still... I don't know of anything that will override what is already in your cache.  Everything I know of applies to the Next time you load the file.
0
 

Author Comment

by:it1000
ID: 39770221
I tried touching all the files. Didn't help.

Anyone have any ideas?
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question