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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:59:55+00:00 2026-05-25T13:59:55+00:00

As the header states, have I understood caching correct, and if so does anyone

  • 0

As the header states, have I understood caching correct, and if so does anyone know any resources which can help me figure out how to do this.

Details:

The php script is called with some POST-parameters that in turn calls an API and output the result, I would like to cache these result so that if the same POST-parameter combination is called twice it fetch from the cache and avoid making another API call.

With my limited knowledge I can think of a session array-solution for this, would that be resonable from a prestanda standpoint?

  • 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-25T13:59:57+00:00Added an answer on May 25, 2026 at 1:59 pm

    About the parameter combination: ask yourself if two users are allowed to see the same result, because your key to save (and later retrieve) the cache will consist of the input parameters as you said. The key need to be unique for obvious reasons, you do not want to show cached data for another set of input variables than it’s intended for.

    The question is, do you need the key to be

    $cache_key = 'search_external_api_user_53'.implode(',', $_POST);
    

    or is

    $cache_key = 'search_external_api'.implode(',', $_POST);
    

    sufficient? (Imploding $_POST is just an example, but it should consist of user data.)

    Footnote: you can not share standard sessions ($_SESSION), instead you could save data in files or memory (like APC or memcached). Saving in files is as easy as:

    function save_cache_in_file($cache_key, $content) {
        $cache_key = md5($cache_key);
        file_put_contents('/tmp/'.$cache_key, serialize($content);
    }
    function get_cache_from_file($cache_key) {
        $cache_key = md5($cache_key);
        if(!file_exists('/tmp/'.$cache_key)) {
            return false;
        }
        return unserialize(file_get_contents('/tmp/'.$cache_key));
    }
    // usage
    $cache_key = 'my_search'.implode(',', $_POST);
    if(!$data_from_external_service = get_cache_from_file($cache_key)) {
        $data_from_external_service = getDataFromElsewhere();
        save_cache_in_file($cache_key, $data_from_external_service);
    }
    // here, $data_from_external_service is always available and cached
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain how compilation works? I can't seem to figure out how compilation
I have written a class which outputs content type information as a header, however
I have a table which consists of a header row, a footer row and
Header, footer and sidebars have fixed position. In the center a content area with
header(Content-type: image/gif); readfile($filename); The above can only be used to show gif images. Is
I have a c++ header file containing a class. I want to use this
I have one map within one header file class: class One { // code
I have a few properties defined in my header file like so @property (assign)
the HTTP specification states that the Transfer-Encoding header is allowed for requests - but
I have a website which uses the custom 404 error handling in PHP/Apache to

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.