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 8328065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:19:32+00:00 2026-06-09T01:19:32+00:00

i’ve friendship_request database table , will if this table have say a million record

  • 0

i’ve friendship_request database table , will if this table have say a million record
when i’ll try to search for requests concerning tom for example and actually there is no friendship request for tom in these million record so which is better:
to index to in memcache when some one send request to tom and then first try to check memcache for tom so if present go to database and make a search query.
OR to make a search query directly without first check memcache
which is faster?
thanks

  • 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-06-09T01:19:34+00:00Added an answer on June 9, 2026 at 1:19 am

    Checking against Memcache first will be faster. Like the name applies, items are stored in memory, and will have less I/O than a database look up. However, Memcached will evict any data if the server’s RAM becomes full. For this reason, it would be unwise to assume that any data put in Memcache will still be there. Even before the item’s time has expired.

    Most Memcache wrappers and API’s will return FALSE, or NOT_FOUND. So your application will just need to identify if your requested items was stored, and if not, check the database. Upon completing the database search, simply record in Memcached the results or no results. This will prevent your application from re-running the same search again.

    Here’s a quick interaction with Memcached

    shell ~> telnet localhost 11211
    tel ~> get tom
           NOT_FOUND
    
    tel ~> set tom 0 86400 5
        ~> 1,2,3
           STORED
    
    tel ~> get tom
           VALUE tom 0 5
           1,2,3
           END
    

    And a quick little PHP class example

    <?php
    class FriendshipRequest extends Memcache {
    
        const KEY_PREFIX = 'fr_' ; // Use constant prefix to create namespace
        const FLAG = 0;            // Flag for memechache storage option
        const EXPIRE = 86400;      // Store for one day
    
        public function __construct() {
        $this->addServer('localhost',11211);
        }
    
        public function __destruct() {
            $this->close();
        }
    
        /**
         * Find a name
         *
         * First check memcached. If not found,
         * search database, and store results
         * in a JSON string
         *
         * @param string $name
         * @return array
         */
        public function find($name) {
                $key = $this->toKey($name);
                $results = $this->get($key);
                if( $results === false ) {
                        $results = $this->databaseSearch($name);
                        $this->set($key,json_encode($results),self::FLAG,self::EXPIRE);
                } else {
                        $results = json_decode($results);
                }
                return $results;
        }
    
        /**
         * Run a database search, and return array of matching ID's
         * @param string $name
         * @return array
         */
        private function databaseSearch($name) {
                $sql = sprintf('SELECT `friend_id` FROM `friendship_request` WHERE `friend_name` LIKE "%s"', mysql_real_escape_string($name));
                $matches = array();
                // Database connection omitted
                $results = mysql_query($sql);
                while( $row = mysql_fetch_object($results) ) {
                 array_push($matches,$results->friend_id);
                }
                mysql_free_result($results);
                return $matches;
        }
    
        /**
         * Create a namespace for key
         * @param string $name
         * @return string
         */
        private function toKey($name) {
                return self::KEY_PREFIX.sha1($name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.