D
D
Denis Potapov2020-03-18 10:48:10
PHP
Denis Potapov, 2020-03-18 10:48:10

What is the best way to cache queries given the search string on photo stocks with API in PHP?

There are photo stocks with APIs like Unsplash, and they have limits on API requests. What is the best way to implement caching in PHP given the search string?
It just seems that given how different words are entered in the search, wouldn't there be too many unique queries that will eventually nullify the effect of caching? Tell me, what is the best way to implement such functionality in order to fit into the limits?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2020-03-18
@potapkzn

Cache through the client by executing an API request from the browser, and send the result to yourself on the backend and cache there, grouping the same responses to different requests into a single group.
If this is not possible, group search queries and link the result to such a group.
For display - find the group for the request and get the answer from the cache of this group.
The binding is simple: one-to-many: responseID->requests.
Optional:
You can put "weights" on each word in the query and create your own dictionary of synonyms to give relevant results from your cache for queries that are similar to the previous ones, but which have never been sent to the photo hosting API.
In other words: make your intermediate search before searching in photo hosting through the API.

A
Anton Shamanov, 2020-03-18
@SilenceOfWinter

read about etag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question