My employer uses forms to help people search for products. The product lists can change from time to time and the forms need to be updated again.

The product information can be accessed through a third party API which I started tinkering with, I've recently built a script that retrieves the information with PHP and creates and populates a form dynamically with Javascript.

So far so good, but...

There are limitations to the API, mainly it can only be accessed a certain number of times per hour, it is probably more than my form/script would use but I want to create a script that is minimally intrusive.

My main question is...

What is the best practice for accessing the information once and storing it long enough to let the API reset? I was wondering about creating a cookie but there is the possibility of users that have them disabled.

(Also, I am doing this as a personal project but I like the people I work for and I think this would help them out.)

Thanks in advance.

  • How often does the data change from the API? Apr 2, 2014 at 3:23
  • Are you able to store anything server-side (database, file)? Any client-side cache you build will have "no" effect if there are many clients with only one/two request. A client-side solution will only work for less clients and more request per client. Apr 2, 2014 at 4:29
  • The API information changes when someone decides to change the item list. This could be once a month to 6 months. I ideally want to do away with the need to sporadically go back and manually add items to the forms. Apr 2, 2014 at 6:37
  • Part of my job is to implement these forms for client's websites (All WordPress). The reason why I want it to be super simple is because after I am done with the script I have plans of turning it into a plugin where all the client has to do is add their corresponding API key to pull the pertinent information to their account. Apr 2, 2014 at 6:42
  • 1
    recommended reading: Why is asking a question on “best practice” a bad thing?
    – gnat
    Apr 10, 2014 at 17:51

1 Answer 1


Usually you can store/cache the API results on your server and perform the query your own cache before API. If you couldn't find anything on the cache, or if the result from cache already was expired or too old, then use the API to get the results and store/update the cache again.

It could be as simple as a table with with query, result, datetime columns or quite complicated if the API is based on HTTP POST requests or if users do have a Custom Queries that could return Customized Results.

For the later case you can implement a cache per request mechanism. It won't be as efficient and easy to implement as the first solution, so don't opt for it unless you are certain that's what you need.

A simple 1:1 cache could be something like an intermediate layer in which you can totally capture the requested API URI and then use it as the key, then store and link the results back to this key. The key could be as simple as a file name and the results could be a JSON file containing results' data.

Later on before sending any request to the API, you should check out your cache directory first to see if you already have such a query/results in the cache or not. It will be useful just if users request a same thing more than once, otherwise, if the requests are mostly unique, don't bother yourself to implement the cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.