Comment on page
Simple caching system to cache the API return in the http GET method, ⚠ by default the caching system is disabled.
We have a timeout system (TTL) for the cached data, by default it is kept for
10 minutes- with the possibility to change it in the settings.
For each URI (with its parameters) a BuntDB database cache file is created.
It was implemented this way with performance in mind - there is no point in putting in a caching system that is slower than the SQL query in PostgreSQL.
- key: URI with all string query parameters
- value: json return (http body)
Is a low-level, in-memory, key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a single writer. It supports custom indexes and geospatial data. It's ideal for projects that need a dependable database and favor speed over data size.
We didn't want to depend on an external database (and we can't create tables in the existing database), with this premise we decided to use an embedded database (write in Go language) and BuntDB proved to be the best option at the moment, here you can see the discussion existing since 2017.
Activating the caching system all endpoints in your api will have the caching system active, following the defined default configuration.
You can customize the configuration made for one (or more) specific endpoints, for example:
/prest/public/my-tableI want more caching time
/prest/public/my-table-uncachedI don't want caching, I need the data that is in the database in "real time
For this configuration, you must use the TOML's
[[cache.endpoints]]node (because it is an array it is not possible to configure it via an environment variable).
Optionally the pREST can be configured by TOML file.
You can follow this sample and create your own
prest.tomlfile and put this on the same folder that you run
enabled = true
time = 10
storagepath = "./"
sufixfile = ".cache.prestd.db"
endpoint = "/prest/public/test"
time = 5
# this endpoint will have no caching system
enabled = false
endpoint = "/prest/public/test-disable"