kyache

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 10 Imported by: 0

README

Kyache

RFC 9111 compliant HTTP shared cache library.

Visit https://kota-yata.github.io/cache-tests/ to see how compliant kyache is with RFC 9111

Installation

go get github.com/kota-yata/kyache

API Usage

As HTTP Transport

Use Kyache as an http.RoundTripper to add caching to any HTTP client:

package main

import (
    "net/http"
    "github.com/kota-yata/kyache"
)

func main() {
    cache := kyache.New(&kyache.Config{})
    
    client := &http.Client{
        Transport: cache,
    }
    
    resp, err := client.Get("https://api.example.com/data")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
}
As HTTP Handler

Use Kyache as an HTTP handler for proxy/gateway scenarios:

package main

import (
    "net/http"
    "net/url"
    "log"
    "github.com/kota-yata/kyache"
)

func main() {
    cache := kyache.New(&kyache.Config{})

    originURL, _ := url.Parse("http://localhost:8080")
    
    handler := cache.Handler(originURL)
    
    log.Println("Cache server running on :8889")
    http.ListenAndServe(":8889", handler)
}
Custom Transport

You can provide a custom transport for advanced networking configurations:

transport := &http.Transport{
    MaxIdleConns:       10,
    IdleConnTimeout:    30 * time.Second,
}

cache := kyache.New(&kyache.Config{
    Transport: transport,
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheServer

type CacheServer struct {
	// contains filtered or unexported fields
}

func New

func New(config *Config) *CacheServer

func (*CacheServer) Handler

func (cs *CacheServer) Handler(originURL *url.URL) http.Handler

func (*CacheServer) RegisterPath

func (cs *CacheServer) RegisterPath(path string, handler http.HandlerFunc)

func (*CacheServer) RoundTrip

func (cs *CacheServer) RoundTrip(req *http.Request) (*http.Response, error)

type Config

type Config struct {
	Transport   http.RoundTripper
	EnableHTTP3 bool
	TLSConfig   *tls.Config
}

Directories

Path Synopsis
client command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL