Database Query Caching


This channel uses the db.querycache module to reduce the performance impact of repeated database queries.

Operations (such as code lookups) that are performed frequently are great candidates for caching. This module maintains an in-memory list of SQL queries, along with the results the database returned for each. When a query is repeated, the module returns the cached result rather than asking the database again. Each result can be saved for a configurable length of time, and each query can be supplied with a default value to return if the result from the database is NULL.

If you have any questions please contact us at

Using the Code [top]

  • Import the Database Query Caching channel from the Builtin: Iguana Tools repository, in the Iguana 6.1 section
  • Experiment with the code to find out how it works
  • Then add the module to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This example modifies the db namespace
  • Adapt the code to your own requirements
  • Use db.cache.query{} anyplace you’re running a query you want to cache
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

The examples shows how to use all the configurable options, including how long to store cached results and how to use default values.

More information [top]


Leave A Comment?

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