httpcache

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Krakend HTTP Cache

A cached http client for the KrakenD framework

Using it

This package exposes two simple factories capable to create a instances of the proxy.HTTPClientFactory and the proxy.BackendFactory interfaces, respectively, embedding an in-memory-cached http client using the package github.com/gregjones/httpcache. The client will cache the responses honoring the defined Cache HTTP header.

import 	(
	"context"
	"net/http"
	"github.com/luraproject/lura/config"
	"github.com/luraproject/lura/proxy"
	"github.com/devopsfaith/krakend-httpcache"
)

requestExecutorFactory := func(cfg *config.Backend) proxy.HTTPRequestExecutor {
	clientFactory := httpcache.NewHTTPClient(cfg)
	return func(ctx context.Context, req *http.Request) (*http.Response, error) {
		return clientFactory(ctx).Do(req.WithContext(ctx))
	}
}

You can create your own proxy.HTTPRequestExecutor and inject it into your BackendFactory

Documentation

Overview

Package httpcache introduces an in-memory-cached http client into the KrakenD stack

Index

Constants

View Source
const Namespace = "github.com/jonathansudibya/krakend-httpcache"

Namespace is the key to use to store and access the custom config data

Variables

This section is empty.

Functions

func BackendFactory

func BackendFactory(cfg *config.Backend) proxy.BackendFactory

BackendFactory returns a proxy.BackendFactory that creates backend proxies using an in-memory-cached http client

func NewHTTPClient

func NewHTTPClient(cfg *config.Backend) client.HTTPClientFactory

NewHTTPClient creates a HTTPClientFactory using an in-memory-cached http client

Types

This section is empty.

Jump to

Keyboard shortcuts

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