|
| 1 | +<p align="center"><a href="https://github.com/darkweak/souin"><img src="docs/img/logo.svg?sanitize=true" alt="Souin logo"></a></p> |
| 2 | + |
| 3 | +# Souin Table of Contents |
| 4 | +1. [Souin reverse-proxy cache](#project-description) |
| 5 | +2. [Environment variables](#environment-variables) |
| 6 | + 2.1. [Required variables](#required-variables) |
| 7 | + 2.2. [Optional variables](#optional-variables) |
| 8 | +3. [Cache system](#cache-system) |
| 9 | +4. [Exemples](#exemples) |
| 10 | + 4.1. [Træfik container](#træfik-container) |
| 11 | + |
| 12 | +[](https://travis-ci.com/Darkweak/Souin) |
| 13 | + |
| 14 | +# <img src="docs/img/logo.svg?sanitize=true" alt="Souin logo" width="30" height="30">ouin reverse-proxy cache |
| 15 | + |
| 16 | +## Project description |
| 17 | +Souin is a new cache system for every reverse-proxy. It will be placed on top of your reverse-proxy like Apache, NGinx or Traefik. |
| 18 | +As it's written in go, it can be deployed on any server and with docker integration, it will be easy to implement it on top of Swarm or kubernetes instance. |
| 19 | + |
| 20 | +## Environment variables |
| 21 | + |
| 22 | +### Required variables |
| 23 | +| Variable | Description | Value exemple | |
| 24 | +|:---:|:---:|:---:| |
| 25 | +|`CACHE_PORT`|The HTTP port Souin will be running to|`80`| |
| 26 | +|`CACHE_TLS_PORT`|The TLS port Souin will be running to|`443`| |
| 27 | +|`REDIS_URL`|The redis instance URL|- `http://redis` (Container way)<br/>`http://localhost:6379` (Local way)| |
| 28 | +|`TTL`|Duration to cache request (in seconds)|10| |
| 29 | +|`REVERSE_PROXY`|The reverse-proxy instance URL like Apache, Nginx, Træfik, etc...|- `http://yourservice` (Container way)<br/>`http://localhost:81` (Local way)| |
| 30 | + |
| 31 | +### Optional variables |
| 32 | +| Variable | Description | Value exemple | |
| 33 | +|:---:|:---:|:---:| |
| 34 | +|`REGEX`|The regex to define URL to not store in cache|`http://domain.com/mypath`| |
| 35 | + |
| 36 | +## Cache system |
| 37 | +The cache is set into redis instance, because we can set, get, update and delete keys as easy as possible. |
| 38 | +To perform with that, redis should be on the same network than Souin instance if you are using docker-compose, then both should be on the same server if you use binaries |
| 39 | +Asynchronously, Souin will request redis instance and the reverse-proxy to get at least one valid response and return to the client the first response caught by Souin. |
| 40 | + |
| 41 | +### Cache invalidation |
| 42 | +The cache invalidation is made for CRUD requests, if you're doing a GET HTTP request, it will serve the cached response if exists then the reverse-proxy response will be served. |
| 43 | +If you're doing a POST, PUT, PATCH or DELETE HTTP request, the related cached get request will be dropped and the list endpoint will be dropped too |
| 44 | +It works very well with plain [API Platform](https://api-platform.com) integration (but not custom actions for now) and CRUD routes |
| 45 | + |
| 46 | +## Exemples |
| 47 | + |
| 48 | +### Træfik container |
| 49 | +[Træfik](https://traefik.io) is a modern reverse-proxy and help you to manage full container architecure projects. |
| 50 | + |
| 51 | +```yaml |
| 52 | +# your-traefik-instance/docker-compose.yml |
| 53 | +version: '3.4' |
| 54 | + |
| 55 | +x-networks: &networks |
| 56 | + networks: |
| 57 | + - your_network |
| 58 | + |
| 59 | +services: |
| 60 | + traefik: |
| 61 | + image: traefik:v2.0 |
| 62 | + ports: |
| 63 | + - "81:80" # Note the 81 to 80 port declaration |
| 64 | + - "444:443" # Note the 444 to 443 port declaration |
| 65 | + command: --providers.docker |
| 66 | + volumes: |
| 67 | + - /var/run/docker.sock:/var/run/docker.sock |
| 68 | + <<: *networks |
| 69 | + |
| 70 | + # your other services here... |
| 71 | + |
| 72 | +networks: |
| 73 | + your_network: |
| 74 | + external: true |
| 75 | +``` |
| 76 | +
|
| 77 | +```yaml |
| 78 | +# your-souin-instance/docker-compose.yml |
| 79 | +version: '3.4' |
| 80 | + |
| 81 | +x-networks: &networks |
| 82 | + networks: |
| 83 | + - your_network |
| 84 | + |
| 85 | +services: |
| 86 | + souin: |
| 87 | + build: |
| 88 | + context: . |
| 89 | + ports: |
| 90 | + - ${CACHE_PORT}:80 |
| 91 | + - ${CACHE_TLS_PORT}:443 |
| 92 | + depends_on: |
| 93 | + - redis |
| 94 | + environment: |
| 95 | + REDIS_URL: ${REDIS_URL} |
| 96 | + TTL: ${TTL} |
| 97 | + CACHE_PORT: ${CACHE_PORT} |
| 98 | + CACHE_TLS_PORT: ${CACHE_TLS_PORT} |
| 99 | + REVERSE_PROXY: ${REVERSE_PROXY} |
| 100 | + REGEX: ${REGEX} |
| 101 | + GOPATH: /app |
| 102 | + volumes: |
| 103 | + - ./cmd:/app/cmd |
| 104 | + <<: *networks |
| 105 | + |
| 106 | + redis: |
| 107 | + image: redis:alpine |
| 108 | + <<: *networks |
| 109 | + |
| 110 | +networks: |
| 111 | + your_network: |
| 112 | + external: true |
| 113 | +``` |
0 commit comments