Skip to content

Commit

Permalink
page dedicated to the caching system
Browse files Browse the repository at this point in the history
brief description of how the prestd caching system works

Signed-off-by: Avelino <avelinorun@gmail.com>
  • Loading branch information
avelino committed Dec 23, 2021
1 parent 12fb0a1 commit ad77ef3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/configurations/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Via environment variables or via toml file.
| PREST\_CACHE | false | embedded cache system |
| PREST\_CACHE_TIME | 10 | TTL in minute (time to live) |
| PREST\_CACHE_STORAGEPATH | ./ | path where the cache file will be created |
| PREST\_CACHE_SUFIXFILE | .cache.prestd.db | |
| PREST\_CACHE_SUFIXFILE | .cache.prestd.db | suffix of the name of the file that is created |
| PREST\_JWT_KEY | | |
| PREST\_JWT_ALGO | HS256 | |
| PREST\_JWT_WHITELIST | [/auth] | |
Expand All @@ -44,7 +44,7 @@ Via environment variables or via toml file.

Optionally the pREST can be configured by TOML file.

You can follow this sample and create your own `prest.toml` file and put this on the same folder that you run `prest` command.
You can follow this sample and create your own `prest.toml` file and put this on the same folder that you run `prestd` command.

```toml
migrations = "./migrations"
Expand Down
51 changes: 51 additions & 0 deletions docs/configurations/cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "Cache"
date: 2021-12-23T19:05:46-03:00
weight: 1
type: homepage
menu: configurations
---

Simple caching system to cache the API return in the http GET method.

We use key and value database embedded in _prestd_ ([BuntDB](https://github.com/tidwall/buntdb)).

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.

## Data Architecture

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)

### Because BuntDB

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**](https://github.com/prest/prest/issues/112).

## Environment vars

| var | default | description |
| --- | --- | --- |
| PREST\_CACHE | false | embedded cache system |
| PREST\_CACHE_TIME | 10 | TTL in minute (time to live) |
| PREST\_CACHE_STORAGEPATH | ./ | path where the cache file will be created |
| PREST\_CACHE_SUFIXFILE | .cache.prestd.db | suffix of the name of the file that is created |

## TOML

Optionally the pREST can be configured by TOML file.

You can follow this sample and create your own `prest.toml` file and put this on the same folder that you run `prestd` command.

```toml
cache = true
[cache]
time = 10
storagepath = "./"
sufixfile = ".cache.prestd.db"
```

0 comments on commit ad77ef3

Please sign in to comment.