Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update README.md #5

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# http-client-cache

http-client-cache is a Go library for transparent HTTP client-side caching using Transport.

Under the standard configuration, the request is retrieved from cache if the request URL, method, and body match.

Only Redis is currently supported as a cache backend.

## Usage

```go
redisCli := redis.NewClient(&redis.Options{Addr: "localhost:6379", DB: 0})
transport := httpclientcache.NewTransport(
rediscache.New(redisCli),
httpclientcache.WithExpiration(5*time.Minute),
)
client := &http.Client{Transport: transport}
```

## Example

```go
Expand All @@ -18,6 +35,7 @@ import (
func main() {
redisCli := redis.NewClient(&redis.Options{Addr: "localhost:6379", DB: 0})
transport := httpclientcache.NewTransport(
// By changing the argument of NewKeyGenerator, the cache space can be separated by such as user.
rediscache.New(redisCli, rediscache.WithKeyGenerator(key.NewKeyGenerator("**userid**"))),
httpclientcache.WithExpiration(5*time.Minute),
)
Expand Down