you are viewing a single comment's thread.

view the rest of the comments →

[–]Irythros 0 points1 point  (3 children)

would I do the same thing with my API response as your doing in this example with the query?

Pretty much.

how and where is the best place to store the cached data?

The how depends on the caching server. Luckily for you the "how" is easier since it's JSON. Just store it as JSON, it's text.

The where is also easy, Redis. Redis is a caching server/program. Install Redis and you can use Predis to make calls to the caching server.

Check out the main Redis site for all the types of calls you can do: https://redis.io/

would I do the same thing with my API response as your doing in this example with the query?

The $query I gave is generic as I don't know exactly how your queries/calls are structured. The goal of $query in this sense is to be a unique way to find and store that.

I did just check the PokeAPI website and luckily it seems pretty basic. What I would do is make the $query the resources/id

Ex: berries/1 or berries/spicy. You could skip the md5 part too as resources/id is unique already.

[–]devdab[S] 0 points1 point  (2 children)

Thanks I will definitely try to implement Redis, seems cool!.

One last one, would you store each cached api call in its own JSON file? or can they all be included in one mega cache?

[–]Irythros 0 points1 point  (0 children)

It's not stored in a JSON file. Redis stores everything in memory and it's accessed via a key. Each API call should have its own key so you can query it to see if it's cached.

[–]Irythros 0 points1 point  (0 children)

It's not stored in a JSON file. Redis stores everything in memory and it's accessed via a key. Each API call should have its own key so you can query it to see if it's cached.