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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:28:48+00:00 2026-06-14T23:28:48+00:00

I have a project that is a results database for several sport event series.

  • 0

I have a project that is a results database for several sport event series.
As you an imagine most the content remains more or less the same.
I would like to cache some of the content to save database queries.

The project is build using PHP and is using a custom MVC.
Where would you add the caching logic?

  • 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-14T23:28:50+00:00Added an answer on June 14, 2026 at 11:28 pm

    Use Memcached. Something like this, where you cache the results of the query, and try retrieving from cache before DB.

    Edit: Added json_encoding the data… json_encode is slightly faster than PHP’s default serialization for arrays, and can be used by other applications accessing the data

    Memcached by default uses FastLZ compression.

    // The ID of the item you're looking for (from $_GET or whatever)
    $id = 1;
    
    // Create a memcached instance
    $m = new Memcached();
    $m->addServer('localhost', 11211);
    
    // Try retrieving the event from memcached
    $data = $m->get('event_' . $id);
    
    if ($data) {
        // If you found data in memcached, decode it for use in code
        $data = json_decode($data);
    } else {
        // If you didn't find the data in memcached, try retrieving from the DB
        $result = mysqli_query('SELECT * FROM events WHERE id = ' . $id);
        // If you found results in the DB...
        if ($data = mysqli_fetch_assoc($result)) {
            // Save them to memcached for future calls
            // Note: here, I'm using the optional param to expire it after 1 day
            $m->set('event_' . $id, json_encode($data), 86400);
        }
    }
    // Now you can use your data
    var_dump($data);
    

    Edited to add comments in code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Django project on Dreamhost server which has several views that returns Json
For a project I have a series of pseudo-repositories that create XML (they aren't
I have a project that may be started on local machine with ./manage.py runserver
I have a project that I have divided quite aggressively into different layers. I
I have a project that using some third-party libraries. My questions is how to
I have a project that is displaying 16px text font at 0.5ems links on
I have a project that's been changed and modified in bits and pieces over
I have a project that I've added to my Jenkins server. The project includes
I have a project that is coded in C. I can build it, change
I have a project that compiles and runs on my system but when I

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.