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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:28:35+00:00 2026-06-06T04:28:35+00:00

$new = $this->memcache->get(posts); if(empty($new)){ // Get the new posts $new = Posts::getNow(10); // Save

  • 0
    $new = $this->memcache->get("posts");
    if(empty($new)){

        // Get the new posts
        $new = Posts::getNow("10");

        // Save them in memcache
        $this->memcache->set('posts', serialize($new), 0, 60*3); // Cache time is 3 min

    // If we found them in cache - load them from there
    } else {

        // Get data from memcache
        $new = unserialize($this->memcache->get("posts"));
    }

The code is very simple if there is data in cache load from there if is not to get them again. The interesting thing is sometimes when I view the site the div is empty and there is no data but when i reload the page there is. Is it possible my view of the site to be when the cache is being eraced ?

  • 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-06T04:28:37+00:00Added an answer on June 6, 2026 at 4:28 am

    That must be timing, you retrieve data from cache twice, once for checking it’s here and second time for unserializing it. Data can be expired just between those calls and we have no control over it

    Just unserialize the data you already got:

    $data = $this->memcache->get("posts");
    if(empty($data)){
        // Get the new posts
        $new = Posts::getNow("10");
        // Save them in memcache
        $this->memcache->set('posts', serialize($new), 0, 60*3);
    } else {
        // Unserialize data instead of retrieving it from cache for second time.
        $new = unserialize($data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this code for example $memcache= new Memcache(); $memcache->connect('127.0.0.1', 11211); $rows2= $memcache->get('therows1'); if($rows2 ==
i made this function: /* MEMCACHE */ function cache_query($sql,$nombre,$tiempo = -1){ $cache = new
I'm new to memcached. Is this code vulnerable to the expired cache race condition?
I'm trying to get the memcache query/result cache working with Oracle. It works flawlessly
I am new to memcache of GAE and I need a help in this.
I am new this sharepoint development and i have task in hand to do
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do
Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.
Im new on this project and am going to write, what i thought was
I'm very new at this, but I need to create new tables from existing

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.