Caching results

Published at: April 4, 2018, 3:35 p.m. in the Documentation

Caching results is one of the most important features of Smappi, which is highly recommended to use.

Important! Cached results are not included in the limit of the selected plan.

Thus, the number of calls to external resources (web-sites as example) will decrease, API owners will reduce their expenses for maintaining Proxy, and API users will not go beyond the limits.

Cache control

At the moment the format is very simple, you need to create the "caches.txt" file in the root of your project (near with file "api.js") with the following contents:

* 3600
myMethod 60

On the left is the name of your function, which you need to cache, and to the right the number of seconds. The "*" mask acts as the default value for all your other functions that you did not define in the "caches.txt" file.

Everything that comes after the number of seconds is ignored, for example, you can write comments:

* 3600
myMethod 60  # myMethod is your function from api.js file

The actual format is similar to all the known "robots.txt", it was chosen for simplicity.
In the future, it is planned to go to the property in the file "package.json", for unification settings.

Example of the contents of the file, you can see here.