HTTP with Caching

Introduction

HTTP with Caching: This module is intended for people who are more experienced with Iguana and webservices. However it is actually very simple to use.

The net.http.cache module in the Iguana Webservices repo enhances the built in net.http APIs to give an optional extra cache_time parameter. This cache_time parameter parameter defaults to 0 seconds which means there is no caching. However if you supply a non-zero value for cache_time parameter then the results of non errored HTTP calls will be cached in a local SQLite database for the number of seconds specified.

Why is this useful? Sometimes web services are slow. Because the translator executes Lua code as you type this makes intellisense and annotations slower to render. Using caching in the editor makes it faster and more convenient to develop code.

The other advantage is when you have a cloud application that has restrictive policies on how many times you can invoke their API on a daily basis. Caching locally reduces the number of calls one has to make to this application.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the HTTP with Caching channel from the Builtin: Iguana Webservices repository
  • Experiment with the code to find out how it works
  • Then add the modules to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module modifies the global namespace
  • Adapt the code to your own requirements
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

The net.http.cache module alters all the relevant net.http.* commands that are built into Iguana to introduce a new cache_time parameter. By default this is set to 0 seconds meaning there is no caching. if you do not use it.

However if you supply a non-zero value for the cache_time parameter then the results of non errored HTTP calls will be cached in a local SQLite database for the number of seconds specified, i.e., this code will cache for up to 60 seconds:

local Response = net.http.get{url="http://www.google.com/", cache_time=60, live=true}

More information [top]

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.