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?
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
or is
sufficient? (Imploding
$_POSTis 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: