Page cache

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have an asp web page which gives the result of a search, and then you
click on links from it to go to linked pages in the same window (ie not
opening new windows).  This is essentially the way most search engine sites
work.  The problem I have it that when you go back to the results page the
(lengthy) search happens again because the page is not in the browser cache
(or the browser thinks it has to re-load it from the server and so it
ignores the cache).

I have looked up lots of (quite confusing) web sites about using http
headers and meta tags to force a page to ignore the local cache and reload
from the server, but I need to force it to USE the cache.  How do I do this?


Re: Page cache

philby wrote:
Quoted text here. Click to load it

You cannot FORCE a browser to do ANYTHING.

Re: Page cache

Quoted text here. Click to load it

I don't think this is a client side issue at all, this has something to do
with the way you are running your script.

If you have something like:
*** Search page ***
<% dim keyword
   keyword = request.querystring("keyword")

   sql = "SELECT results FROM table WHERE filter = " & keyword
   set rs = createobject("ADODB.Recordset")
   rs.Open sql, connectionstring
<form method="get" action="<%=request.servervariables("script_name")%>">
<p><input type="text" name="keyword" value="<%=keyword%>"> <input
type="submit" value="Search"></p></form>

<% if rs.EOF then%>
<p>No results found</p>
<% else
while not rs.EOF
--- results ---
<a href="results.asp?keyword=<%=keyword%>">Result</a>
<% rs.Movenext
   set rs = nothing
   set connection = nothing
   end if
*** Results page ***
<% dim keyword
   keyword = request.querystring("keyword")
<a href="searchpage.asp?keyword=<%=keyword%>">Back to search page</a>

That will let you keep the keyword across pages and return the visitor to
the results originally found. The user can then put in other keyword(s) as
Adrienne Boswell
Please respond to the group so others can share

Re: Page cache

Quoted text here. Click to load it

Firstly, understand that you CANNOT force the client to do anything. But  
you may suggest that it uses the cache. In general, using the cache when  
the back button is hit is the default behaviour, so you don't need to do  
anything -- just avoid sending any cache control headers at all!

If you're still finding that browsers are constantly reloading the search  
results, you can cheat using sessions to store the results. Here's an  
example using PHP:

======================= search.php =======================


   // $q is their search query
   $q = $_GET['q'];

   // header.php uses the variable $title to print a nice heading
   $title = "Search for $q";
   include "header.php";

   // if the user has performed this search before
   if (isset($_SESSION['searches'][$q]))
     print $_SESSION['searches'][$q];

   // otherwise
     // some kind of function to read results from DB
     $results = get_search_results_from_db($q);
     // some kind of function to format them nicely
     $prettyresults = format_results($results);
     $_SESSION['searches'][$q] = $prettyresults;
     print $prettyresults;

   // boring copyright info
   include "footer.php";


Toby A Inkster BSc (Hons) ARCS
Contact Me  ~

Site Timeline