Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My employer uses forms to help people search for products. The product lists can

ID: 647251 • Letter: M

Question

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.

Explanation / Answer

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote