Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:37+00:00 2026-05-24T13:48:37+00:00

Only days ago I started using browser caching, to cache js and css files

  • 0

Only days ago I started using browser caching, to cache js and css files and keep it ” Not Modified “, and it works very good.

Now I want to apply the same way on many pages of the system. For example, I have this page that lists the “users” from the database, and i want to cache the page not to over-load the database with queries.

My question is: is that even a good method (does the page still execute the db query when cached ?) or should I turn to disk caching or memcached ?

header("HTTP/1.1 304 Not Modified");
header("Expires: ".gmdate("D, d M Y H:i:s", time()+(60*86400))." GMT");
header("Cache-Control: must-revalidate");
mysql_query(" SELECT * FROM `users` ");
// list all users 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:48:38+00:00Added an answer on May 24, 2026 at 1:48 pm

    A simple disk caching example, ive used this method when caching dynamic contant that dosent change often like stats, menus, rssfeeds, pages ect..

    <?php 
    $cacheTime=3600; /*1hour*/
    
    if(file_exists('./cache/'.sha1('users').'.php') && $_SESSION['user_status']!=true){
        $FileCreationTime = filectime('./cache/'.sha1('users').'.php');
        /* Calculate file age in seconds*/
        $FileAge = time() - $FileCreationTime;
        /*1h cache*/
        if ($FileAge > ($cacheTime)){unlink('./cache/'.sha1('users').'.php');header('Location: '.$_SERVER['REQUEST_URI']);die();}
        include("./cache/".sha1('users').".php");
        /*Cache is there and not older then 1hour so echo the cache*/
        echo base64_decode($cache);
    }else{
        /*************************************************************/
        //Cache is NOT there or user logged in or older then 1hour so regenerate content
    
        //Do Content and store in $return variable
        $return='';
    
    
        $result = mysql_query(" SELECT * FROM `users` ");
        while($row=mysql_fetch_assoc($result)){
            $return .='<ul>'.$row['user'].'</ul>';
            ...
        }
        ...
        ...
        $return .='bla bla';
        /*************************************************************/
    
        /*Check if not logged in else save*/
        if($_SESSION['user_status']!=true){
            $cache_file_encoded = base64_encode($return);
            $cache_file = <<<CACHE
    <?php 
    /**
    * Cached for:Users Page [{$_SERVER["HTTP_HOST"]}{$_SERVER['REQUEST_URI']}] Base64
    */  
     \$cache ="$cache_file_encoded"; ?>
    CACHE;
            file_put_contents('./cache/'.sha1('users').'.php',$cache_file);
    }
    echo $return;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

3 days ago I started rewriting one of my scripts in OOP using classes
I started learning Rails only a few days ago, but in the mean time
I only want a list of files that have been added (not ones that
Some days ago I started a quick open source project and, when some mates
I started to develop android apps a few days ago, but I'm stuck with
Using only ANSI C, what is the best way to, with fair certainty, determine
Using only VBScript (launched from Windows Scripting Host) can I pull the DLL metadata
A few days ago, I decided to start learning C#. So, I got a
I kind of posted a similar question a couple of days ago but that
From a few days ago I'm facing annoying problems with Visual Studio and .net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.