A cache API is an API that works as a proxy, instead of the application sending the request to the final API it sends it to the cache API. The API will check if the request is in its cache and if not, it makes the request to the final API and stores the entry in its cache.
It may seem that having one more component to jump to flow will be slower, but this is a false impression as the hit ratio will be high and will make the cache API responses much faster than if the request was made directly to the final API, and in addition, we will drastically reduce the amount of requests made to the final API 🎉 🎉.
Use the Let’s Cache API (api.letscache.com) created to help devs, it is completely free and has, in addition to the cache API, a data aggregator where you can make bulk requests and thus reduce response time of multiple requests in a single request.
The API works like the curl command, you need to pass parameters so that it makes the calls to the target hosts. The request information is encrypted with SHA-3 and is stored in the cache with no possibility of being decrypted.
To start using it is very simple, follow the steps below:
1 — Access the disclaimer to learn about API limitations;
2 — Access the API specification (OAS) to know how it works;
3 — Write a simple code inside your App to encapsulate and direct requests to the cache API;
4 — Process the response as if you were processing the response directly from the final API.
Your donation helps us keep the servers running and keep the service free. Send the amount of ether (ETH) you want to the address below:
To demonstrate a simple call using LetsCache we will use this great API, Open Brewery DB 🍻.
“Open Brewery DB is a free dataset and API with public information on breweries, cideries, brewpubs, and bottleshops.” — openbrewerydb website
Let’s use an example taken from the documentation.
$ curl https://api.openbrewerydb.org/breweries/madtree-brewing-cincinnati{"id":"madtree-brewing-cincinnati","name":"MadTree Brewing","brewery_type":"regional","street":"3301 Madison Rd","address_2":null,"address_3":null,"city":"Cincinnati","state":"Ohio","county_province":null,"postal_code":"45209-1132","country":"United States","longitude":"-84.4239715","latitude":"39.1563725","phone":"5138368733","website_url":"http://www.madtreebrewing.com","updated_at":"2022-08-20T02:56:08.975Z","created_at":"2022-08-20T02:56:08.975Z"}
This same command can be performed using LetsCache like this:
$ curl https://api.letscache.com/cache -X PUT \ -d '{"url":"https://api.openbrewerydb.org/breweries/madtree-brewing-cincinnati"}'{"id":"madtree-brewing-cincinnati","name":"MadTree Brewing","brewery_type":"regional","street":"3301 Madison Rd","address_2":null,"address_3":null,"city":"Cincinnati","state":"Ohio","county_province":null,"postal_code":"45209-1132","country":"United States","longitude":"-84.4239715","latitude":"39.1563725","phone":"5138368733","website_url":"http://www.madtreebrewing.com","updated_at":"2022-08-20T02:56:08.975Z","created_at":"2022-08-20T02:56:08.975Z"}
The difference is that using Let’sCache the next requests will be answered with the cache response and the response time will be even faster. Let’s see what the request would look like using Postman.
First directly to the final API:
Then, using Let’sCache:
We see that the response time for the first request is equivalent to the response time if we made the request directly to the final API.
Let’s run the same request again.
Notice that the response time has dropped a lot because now the response is being returned by the cache 🚀.
Let’sCache it also has bulk requests so your application can benefit from call parallelism and save time on data aggregations. With bulk you can make just one request to Let’sCache and receive responses quickly, with the slowest request time being the maximum response time.