Skip to content

Commit 9487c7e

Browse files
committed
v0.1.1
1 parent 4f972cb commit 9487c7e

17 files changed

+53
-32
lines changed

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=neurocode-io_cache-offloader&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=neurocode-io_cache-offloader)
1111

1212

13+
# Install
14+
15+
pre go 1.15
16+
go get github.com/neurocode-io/cache-offloader@v0.1.1
17+
18+
after go 1.15
19+
go install github.com/neurocode-io/cache-offloader@v0.1.1
20+
21+
22+
# Using the service
23+
24+
This service provides a stale while revalidate cache for your HTTP requests. If a request is made to a URL that is already in the cache, the cache will be used. The cache will also be used if the cache is stale. However, an asynchronous request will be made to the server to refresh the cache if the cache is stale.
25+
26+
Check out the `dev.env` file for configuration options.
27+
28+
Essentially you can choose between in-memory or redis persistence.
29+
30+
Redis persistence is recommended when you have multiple processes running the service (or multiple pods).
31+
32+
33+
The environment variable CACHE_IGNORE_ENDPOINTS defines the endpoints that are allowed to passthrough without any checks from this service.
34+
35+
You can also choose to incude query parameters in the cache key. `CACHE_SHOULD_HASH_QUERY` is a boolean flag that defines whether or not to hash the query parameters.
36+
37+
By `CACHE_HASH_QUERY_IGNORE` you can define which query parameters should be ignored when hashing the query.
38+
39+
Another useful configuration option is `CACHE_STALE_WHILE_REVALIDATE_SEC`. This defines the time in seconds that the cache entry is considered stale and the cache is revalidated asynchronously.
40+
41+
1342
# Dev
1443

1544
```
@@ -27,11 +56,3 @@ http localhost:8000/probes/readiness
2756
```
2857
go install github.com/golang/mock/mockgen@latest
2958
```
30-
31-
32-
# Configuration
33-
... ADD MORE
34-
35-
CACHE_IGNORE_ENDPOINTS=/management/prometheus, /api-docs
36-
37-
Note that the environment variable CACHE_IGNORE_ENDPOINTS defines the endpoints that are allowed to passthrough without any checks from this service.

cmd/cache-offloader.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"strings"
55
"time"
66

7+
"github.com/neurocode-io/cache-offloader/config"
8+
"github.com/neurocode-io/cache-offloader/pkg/client"
9+
"github.com/neurocode-io/cache-offloader/pkg/http"
10+
"github.com/neurocode-io/cache-offloader/pkg/metrics"
11+
"github.com/neurocode-io/cache-offloader/pkg/probes"
12+
"github.com/neurocode-io/cache-offloader/pkg/storage"
13+
"github.com/neurocode-io/cache-offloader/pkg/worker"
714
"github.com/rs/zerolog"
815
"github.com/rs/zerolog/log"
916
"github.com/rs/zerolog/pkgerrors"
10-
"neurocode.io/cache-offloader/config"
11-
"neurocode.io/cache-offloader/pkg/client"
12-
"neurocode.io/cache-offloader/pkg/http"
13-
"neurocode.io/cache-offloader/pkg/metrics"
14-
"neurocode.io/cache-offloader/pkg/probes"
15-
"neurocode.io/cache-offloader/pkg/storage"
16-
"neurocode.io/cache-offloader/pkg/worker"
1717
)
1818

1919
func getInMemoryStorage(cfg config.Config) http.Cacher {

dev.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ServerConfig
22
SERVER_PORT=8000
3-
SERVER_LOG_LEVEL=ERROR
3+
SERVER_LOG_LEVEL=debug
44
SERVER_STORAGE=memory
55
DOWNSTREAM_HOST=http://httpbin.org
66
SHUTDOWN_GRACE_PERIOD=30

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module neurocode.io/cache-offloader
1+
module github.com/neurocode-io/cache-offloader
22

33
go 1.18
44

pkg/client/redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66

77
"github.com/go-redis/redis/v8"
8+
"github.com/neurocode-io/cache-offloader/config"
89
"github.com/rs/zerolog/log"
9-
"neurocode.io/cache-offloader/config"
1010
)
1111

1212
type RedisClient struct {

pkg/http/cache-mock_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/http/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616

1717
"github.com/rs/zerolog/log"
1818

19-
"neurocode.io/cache-offloader/config"
20-
"neurocode.io/cache-offloader/pkg/model"
19+
"github.com/neurocode-io/cache-offloader/config"
20+
"github.com/neurocode-io/cache-offloader/pkg/model"
2121
)
2222

2323
//go:generate mockgen -source=./cache.go -destination=./cache-mock_test.go -package=http

pkg/http/cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"testing"
1010

1111
gomock "github.com/golang/mock/gomock"
12+
"github.com/neurocode-io/cache-offloader/config"
13+
"github.com/neurocode-io/cache-offloader/pkg/model"
1214
"github.com/stretchr/testify/assert"
13-
"neurocode.io/cache-offloader/config"
14-
"neurocode.io/cache-offloader/pkg/model"
1515
)
1616

1717
type responseMatcher struct {

pkg/http/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"syscall"
1010
"time"
1111

12+
"github.com/neurocode-io/cache-offloader/config"
1213
"github.com/rs/zerolog/log"
13-
"neurocode.io/cache-offloader/config"
1414
)
1515

1616
type ServerOpts struct {

pkg/storage/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package storage
33
import (
44
"time"
55

6-
"neurocode.io/cache-offloader/pkg/model"
6+
"github.com/neurocode-io/cache-offloader/pkg/model"
77
)
88

99
func getSize(value model.Response) float64 {

0 commit comments

Comments
 (0)