What is the best way to code a caching script?

by Nite
1 replies
Hello. I have created a PHP script, and in order to prevent excessive hammering of the product API that supplies the shopping content to the script, I need to code in some kind of caching. But, I'm not sure where to begin.

I was thinking about creating a cache file for each API request using some kind of output cache, and then keeping that file around for a few days. After about 7 days, the file would be deleted. This sounds good in theory, but I don't know how to do this. It seems that searching google produces results related to caching mySQL results.

I'm not asking to be spoon fed, and I'm sure I can figure this out eventually. I would appreciate being point in the right direction, and I would like to hear solutions about what other people have found. I've been coding for just a few months now, and I'm just too new to really know what's out there and what's "best."

Thanks!
- Nite
#caching #code #script
  • Profile picture of the author wayfarer
    A common way to do it is to capture everything using output buffering, save everything in a file, and only execute the entire page according to timestamp information saved in a related file.

    Here's an example of this, though I'm not sure exactly how it applies to your situation since you're working with an API, which may have complexity that I'm unaware of: Using Output Buffering to Cache PHP Files < PHP | The Art of Web
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[4380955].message }}

Trending Topics