SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to implement a simple cache system ?

    I'm having some little success with my news/weblog script, and was thinking about giving it one advantage of flat-files driven script: already generated files.

    I would go for a cache system that would check for the last time the weblog has been updated, and if that's more recently than the cached file, serve the page and rebuild the file. Of course searches and things that use the querystring would always be dynamically generated.

    Now I have two questions:
    1/ How to check if the querystring is empty ?
    2/ How would you go about implementing such a system ?

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can check if the query string is empty like this:

    if (empty($QUERY_STRING))
    {
    // No query string
    }

    As for the actual caching, the obvious thing is just to generate the whole page and store the HTML in a flat file somewhere, then like you said you can check the "last modified" time of that file to see how up to date the cache is.

    If your page is generated with lots of seperate echo() statements an easy way of grabbing the contents of the page into a variable rather than displaying it is to use output buffering - turn it on, run the code as normal then at the end grab the contents of the output buffer into your variable before saving it in a file. More info on that can be found here:

    http://www.php.net/manual/en/ref.outcontrol.php

  3. #3
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually.. you could start the output buffer at the top, end it at the bottom, flush it, and there ya go

    I would look around at http://zend.com as well
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this may interest you:

    http://www.0x00.org/php/phpCache/

    I use it. Its very customizeable as far as caching goes, for instance I edited it to keys the caches on path_info in addition to the other things.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •