webserver

command
v0.0.0-...-41babec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 12 Imported by: 0

README

Webserver example

It shows:

  • In-memory cache
  • NATS wrapper with In-memory cache
  • Redis cache
  • Invalidation by cache type and by tag
Start
Prepare
# Start NATS
docker run -d --name nats -p 4222:4222 -p 6222:6222 -p 8222:8222 nats
# Start Redis
docker run -d --name redis -p6379:6379 redis
Start several instances on different ports
go run *.go :8080
go run *.go :8081
...
Testing

Get data from store

time curl http://127.0.0.1:8080/orders | jq
# ~1 sec
time curl http://127.0.0.1:8080/goods | jq
# ~1 sec

Playing with in-memory cache

time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8081/orders/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~0.01 sec
time curl http://127.0.0.1:8081/orders/inmemory | jq
# ~0.01 sec
### Invalidation
time curl http://127.0.0.1:8080/invalidate/orders/inmemory
# OK
time curl http://127.0.0.1:8081/orders/inmemory | jq
# ~0.01 sec
time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~1 sec

Playing with in-memory + NATS

time curl http://127.0.0.1:8080/orders/nats | jq
# ~1 sec
time curl http://127.0.0.1:8081/orders/nats | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/nats | jq
# ~0.01 sec
time curl http://127.0.0.1:8081/orders/nats | jq
# ~0.01 sec
### Invalidation
time curl http://127.0.0.1:8080/invalidate/orders/nats
# OK
time curl http://127.0.0.1:8081/orders/nats | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/nats | jq
# ~1 sec

Playing with Redis cache

time curl http://127.0.0.1:8080/orders/redis | jq
# ~1 sec
time curl http://127.0.0.1:8081/orders/redis | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/redis | jq
# ~0.01 sec
time curl http://127.0.0.1:8081/orders/redis | jq
# ~0.01 sec
### Invalidation
time curl http://127.0.0.1:8080/invalidate/orders/redis
# OK
time curl http://127.0.0.1:8081/orders/redis | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/redis | jq
# ~1 sec

Checking invalidation by tag

time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8080/goods/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~0.01 sec
time curl http://127.0.0.1:8080/goods/inmemory | jq
# ~0.01 sec
### Invalidation
#### Tag: orders
time curl http://127.0.0.1:8080/invalidate/tag/orders
# OK
time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8080/goods/inmemory | jq
# ~0.01 sec
#### Tag: goods (Tag exists in Orders and Goods caches)
time curl http://127.0.0.1:8080/invalidate/tag/goods
# OK
time curl http://127.0.0.1:8080/orders/inmemory | jq
# ~1 sec
time curl http://127.0.0.1:8080/goods/inmemory | jq
# ~1 sec

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL