From 54ed9be34124b6361e64d97dffa87fe47481f173 Mon Sep 17 00:00:00 2001 From: ASAKURA Kazuki <32762324+Arthur1@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:16:45 +0900 Subject: [PATCH] update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index ad8b947..5be66d7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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), )