HTTP Library
The HTTP library provides a simple method to add response caching to the built-in HTTP functions in the Translator. This is especially useful when developing API integrations as it allows you to reduce the number of unnecessary API calls and avoid maxing out any request limits.
Simply add the library to the Translator project using +LIBRARY and the built-in functions will automatically updated with the caching ability. The caching can be activated by providing a time in seconds to the cache_time
parameter of the net.http.* function. An example of the help can be seen below:
The library also provides a net.http.cache
function which returns the SQLite database connection object for the cache. You can use it to interact with the cache to manually clear or view its contents. Try the below code snippet in your Translator to check it out:
-- Make a HTTP request
local Response, Code, Headers = net.http.get{
url = 'http://www.google.com/',
live = true,
cache_time = 60 -- Cache for 60 seconds
}
trace(Response)
trace(Code)
trace(Headers)
-- Check the cache
local Store = net.http.cache()
Store:info() -- Get details of what's currently in the cache
Store:reset() -- Manually clear the cache