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

  • SEARCH
  • Home
  • 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 3610506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:45:38+00:00 2026-05-18T21:45:38+00:00

In my CMS, sometimes I will make redundant queries because everything is independent. Is

  • 0

In my CMS, sometimes I will make redundant queries because everything is independent. Is it ok to cache queries like this?:

        global $cache_query, $cache_result;
        if(!is_array($cache_query) || !is_array($cache_result) || !in_array($q,$cache_query))
        {//The query is new. 
            $r = query_($q);
            $cache_query[] = $q;
            $cache_result[] = $r;
        }
        else
        {//The query is cached.
            foreach($cache_query as $k=>$c) // Cycle through my cached queries to find the key. Is there an getElementKey function?
                if($c == $q) {
                    if(@mysql_fetch_array($cache_result[$k])) // is the resource is still valid?
                        mysql_data_seek($cache_result[$k], 0); // rewind the pointer
                    else
                        $cache_result[$k] = query_($q); // reset the resource
                    $r = $cache_result[$k];
                    break;
                }
        }
        return $r;

OR is a better practice to just make a new query each time?
$q is my query, and the function query_() returns a resource and logs if something goes wrong.

  • 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-18T21:45:39+00:00Added an answer on May 18, 2026 at 9:45 pm

    Database queries are frequently a huge portion of your execution time, so if you can cache them you should.

    That said, it might be better to save them off in named variables (or named variables in an associative array). Why are you walking through the array instead of just doing:

    if(isset($cache_result[$query])) {
        return $cache_result[$query];
    } else {
        // not cached
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody have any idea how I would make this shorter and less redundant:
My CMS system allows people to post some SWF's on my homepage however, sometimes
In my application's CMS, I have an edit items form. The items users will
The orchard asp.net cms. Is it an open source?Because In my all downloads i
I'm in Symphony CMS trying to return an article image like so. <img src={$workspace}/uploads/{/data/news-articles/entry/image-thumbnail}/>
We're building a CMS. The site will be built and managed by the users
cms is generating content in this format. <ul id=slide_nav class=tabs> <a name=ctn2363_2465 id=ctn2363_2465 class=hidden></a><li
My CMS links to other sites for convenience and I'd like to hide the
I am using Hotaru CMS with the Image Upload plugin, I get this error
I add C# group too in this, because this is not VB problem but

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.