|
1 | | -# hache |
2 | | -Cache on Go HTTP Client |
| 1 | +# Docs |
| 2 | + |
| 3 | +Howdy there!!! |
| 4 | + |
| 5 | +Usually when we want to integrate with cache (let's say Redis), we usually have to do many changes in our code. |
| 6 | +What if, we just inject the cache to the HTTP client. So we don't have to create many changes in each line of our code to get the data from Cache, do the validation etc. |
| 7 | + |
| 8 | +## Introduce Hache: Injecte-able HTTP Cache for Golang HTTP Client |
| 9 | + |
| 10 | +[](https://travis-ci.org/bxcodec/hache) |
| 11 | +[](https://codecov.io/gh/bxcodec/hache) |
| 12 | +[](https://goreportcard.com/report/github.com/bxcodec/hache) |
| 13 | +[](https://github.com/bxcodec/hache/blob/master/LICENSE) |
| 14 | +[](https://godoc.org/github.com/bxcodec/hache) |
| 15 | + |
| 16 | +This package is used for caching your http request results from the server. Example how to use can be seen below. |
| 17 | + |
| 18 | +## Index |
| 19 | + |
| 20 | +* [Support](#support) |
| 21 | +* [Getting Started](#getting-started) |
| 22 | +* [Example](#example) |
| 23 | +* [Limitation](#limitation) |
| 24 | +* [Contribution](#contribution) |
| 25 | + |
| 26 | + |
| 27 | +## Support |
| 28 | + |
| 29 | +You can file an [Issue](https://github.com/bxcodec/hache/issues/new). |
| 30 | +See documentation in [Godoc](https://godoc.org/github.com/bxcodec/hache) |
| 31 | + |
| 32 | + |
| 33 | +## Getting Started |
| 34 | + |
| 35 | +#### Download |
| 36 | + |
| 37 | +```shell |
| 38 | +go get -u github.com/bxcodec/hache/v3 |
| 39 | +``` |
| 40 | +# Example |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +Example how to use more details can be seen in the sample folder: [/sample](/sample) |
| 45 | + |
| 46 | +Short example: |
| 47 | + |
| 48 | +```go |
| 49 | + |
| 50 | +// Inject the HTTP Client with Hache |
| 51 | +client := &http.Client{} |
| 52 | +err := hache.NewWithInmemoryCache(client, time.Second*60) |
| 53 | +if err != nil { |
| 54 | + log.Fatal(err) |
| 55 | +} |
| 56 | + |
| 57 | +// And your HTTP Client already supported for HTTP Cache |
| 58 | +// To verify you can run a request in a loop |
| 59 | + |
| 60 | +for i:=0; i< 10; i++ { |
| 61 | + startTime := time.Now() |
| 62 | + req, err := http.NewRequest("GET", "https://bxcodec.io", nil) |
| 63 | + if err != nil { |
| 64 | + log.Fatal((err)) |
| 65 | + } |
| 66 | + |
| 67 | + res, err := client.Do(req) |
| 68 | + if err != nil { |
| 69 | + log.Fatal(err) |
| 70 | + } |
| 71 | + |
| 72 | + fmt.Printf("Response time: %vms\n", time.Since(startTime).Microseconds()) |
| 73 | + fmt.Println("Status Code", res.StatusCode) |
| 74 | +} |
| 75 | +// See the response time, it will different on each request and will go smaller. |
| 76 | +``` |
| 77 | + |
| 78 | +### Inject with your Redis Service |
| 79 | +//TODO(bxcodec) |
| 80 | + |
| 81 | + |
| 82 | +## Contribution |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +To contrib to this project, you can open a PR or an issue. |
0 commit comments