All Projects → victorspringer → Http Cache

victorspringer / Http Cache

Licence: mit
High performance Golang HTTP middleware for server-side application layer caching, ideal for REST APIs

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Http Cache

Faraday Http Cache
a faraday middleware that respects HTTP cache
Stars: ✭ 276 (+50%)
Mutual labels:  middleware, cache
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (+103.26%)
Mutual labels:  middleware, cache
express-view-cache
Unobtrusive solution to express framework - cache rendered page, without database requests and rendering.
Stars: ✭ 20 (-89.13%)
Mutual labels:  middleware, cache
Outputcache
Cache api responses using Redis, Memcached or any cache provider for NodeJS
Stars: ✭ 9 (-95.11%)
Mutual labels:  middleware, cache
Guzzle Cache Middleware
A Guzzle Cache middleware
Stars: ✭ 50 (-72.83%)
Mutual labels:  middleware, cache
Guzzle Advanced Throttle
A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get the response from cache when the rate limit is exceeded or always get a cached value to spare your rate limits. Using wildcards in host names is also supported.
Stars: ✭ 120 (-34.78%)
Mutual labels:  middleware, cache
Guzzle Cache Middleware
A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.
Stars: ✭ 325 (+76.63%)
Mutual labels:  middleware, cache
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+420.11%)
Mutual labels:  middleware, cache
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-80.98%)
Mutual labels:  middleware, cache
Dotweb
Simple and easy go web micro framework
Stars: ✭ 1,354 (+635.87%)
Mutual labels:  middleware, cache
Strapi Middleware Cache
🔌 A cache middleware for https://strapi.io
Stars: ✭ 146 (-20.65%)
Mutual labels:  middleware, cache
Micro Aws Lambda
A 7KB and 0 dependencies AWS Lambda library which supports middleware and easy debug.
Stars: ✭ 181 (-1.63%)
Mutual labels:  middleware
Laravel Http2 Server Push
A middleware package for Laravel to enable server push for your script, style, and image assets.
Stars: ✭ 174 (-5.43%)
Mutual labels:  middleware
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (-5.98%)
Mutual labels:  middleware
Flatcache
Implementation of Soroush Khanlou's Flat Cache.
Stars: ✭ 173 (-5.98%)
Mutual labels:  cache
Recent Images
Do you noticed the new feature of Telegram or Instagram?! They show your latest images when you try to attach or post a picture. So I developed this library the same with lots of customization. Simple way to get all images of device based on date taken, name, id and other customization
Stars: ✭ 182 (-1.09%)
Mutual labels:  cache
Dyld cache extract
A macOS utility to extract dynamic libraries from the dyld_shared_cache of macOS and iOS.
Stars: ✭ 180 (-2.17%)
Mutual labels:  cache
Ktvhttpcache
A powerful media cache framework.
Stars: ✭ 2,113 (+1048.37%)
Mutual labels:  cache
Nginx Helper
Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
Stars: ✭ 170 (-7.61%)
Mutual labels:  cache
Tmp Cache
A least-recently-used cache in 35 lines of code~!
Stars: ✭ 170 (-7.61%)
Mutual labels:  cache

http-cache

Build Status Coverage Status

This is a high performance Golang HTTP middleware for server-side application layer caching, ideal for REST APIs.

It is simple, super fast, thread safe and gives the possibility to choose the adapter (memory, Redis, DynamoDB etc).

The memory adapter minimizes GC overhead to near zero and supports some options of caching algorithms (LRU, MRU, LFU, MFU). This way, it is able to store plenty of gigabytes of responses, keeping great performance and being free of leaks.

Getting Started

Installation

go get github.com/victorspringer/http-cache

Usage

This is an example of use with the memory adapter:

package main

import (
    "fmt"
    "net/http"
    "os"
    "time"
    
    "github.com/victorspringer/http-cache"
    "github.com/victorspringer/http-cache/adapter/memory"
)

func example(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Ok"))
}

func main() {
    memcached, err := memory.NewAdapter(
        memory.AdapterWithAlgorithm(memory.LRU),
        memory.AdapterWithCapacity(10000000),
    )
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    cacheClient, err := cache.NewClient(
        cache.ClientWithAdapter(memcached),
        cache.ClientWithTTL(10 * time.Minute),
        cache.ClientWithRefreshKey("opn"),
    )
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    handler := http.HandlerFunc(example)

    http.Handle("/", cacheClient.Middleware(handler))
    http.ListenAndServe(":8080", nil)
}

Example of Client initialization with Redis adapter:

import (
    "github.com/victorspringer/http-cache"
    "github.com/victorspringer/http-cache/adapter/redis"
)

...

    ringOpt := &redis.RingOptions{
        Addrs: map[string]string{
            "server": ":6379",
        },
    }
    cacheClient := cache.NewClient(
        cache.ClientWithAdapter(redis.NewAdapter(ringOpt)),
        cache.ClientWithTTL(10 * time.Minute),
        cache.ClientWithRefreshKey("opn"),
    )

...

Benchmarks

The benchmarks were based on allegro/bigache tests and used to compare it with the http-cache memory adapter.
The tests were run using an Intel i5-2410M with 8GB RAM on Arch Linux 64bits.
The results are shown below:

Writes and Reads

cd adapter/memory/benchmark
go test -bench=. -benchtime=10s ./... -timeout 30m

BenchmarkHTTPCacheMamoryAdapterSet-4             5000000     343 ns/op    172 B/op    1 allocs/op
BenchmarkBigCacheSet-4                           3000000     507 ns/op    535 B/op    1 allocs/op
BenchmarkHTTPCacheMamoryAdapterGet-4            20000000     146 ns/op      0 B/op    0 allocs/op
BenchmarkBigCacheGet-4                           3000000     343 ns/op    120 B/op    3 allocs/op
BenchmarkHTTPCacheMamoryAdapterSetParallel-4    10000000     223 ns/op    172 B/op    1 allocs/op
BenchmarkBigCacheSetParallel-4                  10000000     291 ns/op    661 B/op    1 allocs/op
BenchmarkHTTPCacheMemoryAdapterGetParallel-4    50000000    56.1 ns/op      0 B/op    0 allocs/op
BenchmarkBigCacheGetParallel-4                  10000000     163 ns/op    120 B/op    3 allocs/op

http-cache writes are slightly faster and reads are much more faster.

Garbage Collection Pause Time

cache=http-cache go run benchmark_gc_overhead.go

Number of entries:  20000000
GC pause for http-cache memory adapter:  2.445617ms

cache=bigcache go run benchmark_gc_overhead.go

Number of entries:  20000000
GC pause for bigcache:  7.43339ms

http-cache memory adapter takes way less GC pause time, that means smaller GC overhead.

Roadmap

  • Make it compliant with RFC7234
  • Add more middleware configuration (cacheable status codes, paths etc)
  • Develop gRPC middleware
  • Develop Badger adapter
  • Develop DynamoDB adapter
  • Develop MongoDB adapter

Who's using?

Godoc Reference

License

http-cache is released under the MIT License.

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].