All Projects → bxcodec → Httpcache

bxcodec / Httpcache

Licence: mit
Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Httpcache

Use Axios Request
Data fetching is easy with React Hooks for axios!
Stars: ✭ 38 (+123.53%)
Mutual labels:  cache, http-client
Cashew
A simple and elegant yet powerful HTTP client cache for .NET
Stars: ✭ 70 (+311.76%)
Mutual labels:  cache, http-client
Zio Tls Http
100% non-blocking, Java NIO only( inspired by zio-nio) , JSON HTTP server based on Scala ZIO library. Everything including TLS encryption modeled as ZIO effects, convenient route DSL similar to https4s, up to 30K TPS local JSON transaction with 25 threads on 6 cores(i7) with ZIO fibers.
Stars: ✭ 71 (+317.65%)
Mutual labels:  cache, http-client
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+42111.76%)
Mutual labels:  http-client
Gocache
☔️ A complete Go cache library that brings you multiple ways of managing your caches
Stars: ✭ 775 (+4458.82%)
Mutual labels:  cache
Cleanmywechat
自动删除 PC 端微信缓存数据,包括从所有聊天中自动下载的大量文件、视频、图片等数据内容,解放你的空间。
Stars: ✭ 816 (+4700%)
Mutual labels:  cache
Lazycache
An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
Stars: ✭ 901 (+5200%)
Mutual labels:  cache
Rome
Carthage cache for S3, Minio, Ceph, Google Storage, Artifactory and many others
Stars: ✭ 724 (+4158.82%)
Mutual labels:  cache
Redux Axios Middleware
Redux middleware for fetching data with axios HTTP client
Stars: ✭ 902 (+5205.88%)
Mutual labels:  http-client
Django Cachalot
No effort, no worry, maximum performance.
Stars: ✭ 790 (+4547.06%)
Mutual labels:  cache
Java Knowledge Mind Map
【🌱🌱Java服务端知识技能图谱】用思维脑图梳理汇总Java服务端知识技能
Stars: ✭ 787 (+4529.41%)
Mutual labels:  cache
Smartsql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
Stars: ✭ 775 (+4458.82%)
Mutual labels:  cache
Once
A magic memoization function
Stars: ✭ 821 (+4729.41%)
Mutual labels:  cache
Vimediacache
Cache media file while play media using AVPlayer
Stars: ✭ 758 (+4358.82%)
Mutual labels:  cache
Go Reflectx
Go reflection library to find struct field by its tag
Stars: ✭ 19 (+11.76%)
Mutual labels:  cache
Gout
gout to become the Swiss Army Knife of the http client @^^@---> gout 是http client领域的瑞士军刀,小巧,强大,犀利。具体用法可看文档,如使用迷惑或者API用得不爽都可提issues
Stars: ✭ 749 (+4305.88%)
Mutual labels:  http-client
React Native Cached Image
CachedImage component for react-native
Stars: ✭ 890 (+5135.29%)
Mutual labels:  cache
Yac
A fast, lock-free, shared memory user data cache for PHP
Stars: ✭ 782 (+4500%)
Mutual labels:  cache
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+41352.94%)
Mutual labels:  http-client
Requests3
Requests 3.0, for Humans and Machines, alike. 🤖
Stars: ✭ 813 (+4682.35%)
Mutual labels:  http-client

httpcache, inject-able HTTP cache in Golang

Howdy there!!!

Usually when we want to integrate with cache (let's say Redis), we usually have to do many changes in our code. What if, we just inject the cache to the HTTP client. So we don't have to create many changes in every line of our code to support the cache features? With only less than 10 line of code, you can got a complete implementations of HTTP Cache based on RFC 7234

Build Status License GoDoc Go.Dev

This package is used for caching your http request results from the server. Example how to use can be seen below.

Index

Support

You can file an Issue. See documentation in Godoc or in go.dev

Getting Started

Download

go get -u github.com/bxcodec/httpcache

Example with Inmemory Storage


Example how to use more details can be seen in the example file: ./example_inmemory_storage_test.go

Short example:


// Inject the HTTP Client with httpcache
client := &http.Client{}
_, err := httpcache.NewWithInmemoryCache(client, true, time.Second*60)
if err != nil {
  log.Fatal(err)
}
 
// And your HTTP Client already supported for HTTP Cache
// To verify you can run a request in a loop

for i:=0; i< 10; i++ {
  startTime := time.Now()
  req, err := http.NewRequest("GET", "https://bxcodec.io", nil)
  if err != nil {
    log.Fatal((err))
  }

  res, err := client.Do(req)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("Response time: %vms\n", time.Since(startTime).Microseconds())
  fmt.Println("Status Code", res.StatusCode)
}
// See the response time, it will different on each request and will go smaller.

Example with Custom Storage

You also can use your own custom storage, what you need to do is implement the cache.ICacheInteractor interface. Example how to use more details can be seen in the example file: ./example_custom_storage_test.go

Example:

client := &http.Client{}
_, err := httpcache.NewWithCustomStorageCache(client,true, mystorage.NewCustomInMemStorage())
if err != nil {
	log.Fatal(err)
}

About RFC 7234 Compliance

You can disable/enable the RFC Compliance as you want. If RFC 7234 is too complex for you, you can just disable it by set the RFCCompliance parameter to false

_, err := httpcache.NewWithInmemoryCache(client, false, time.Second*60)
// or 
_, err := httpcache.NewWithCustomStorageCache(client,false, mystorage.NewCustomInMemStorage())

The downside of disabling the RFC Compliance, All the response/request will be cached automatically. Do with caution.

TODOs

Inspirations and Thanks

  • pquerna/cachecontrol for the Cache-Header Extraction
  • bxcodec/gothca for in-memory cache. *Notes: if you find another library that has a better way for inmemm cache, please raise an issue or submit a PR

Contribution


To contrib to this project, you can open a PR or an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].