caching

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XCacheHeader   = "X-Cache"
	StatusHit      = "HIT"
	StatusMiss     = "MISS"
	StatusBypass   = "BYPASS"
	StatusError    = "ERROR"
	StatusDisabled = "DISABLED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheQueryResponseFn

type CacheQueryResponseFn func(context.Context, *backend.QueryDataResponse)

type CacheResourceResponseFn

type CacheResourceResponseFn func(context.Context, *backend.CallResourceResponse)

type CachedQueryDataResponse

type CachedQueryDataResponse struct {
	// The cached data response associated with a query, or nil if no cached data is found
	Response *backend.QueryDataResponse
	// A function that should be used to cache a QueryDataResponse for a given query.
	// It can be set to nil by the method implementation (if there is an error, for example), so it should be checked before being called.
	UpdateCacheFn CacheQueryResponseFn
}

type CachedResourceDataResponse

type CachedResourceDataResponse struct {
	// The cached response associated with a resource request, or nil if no cached data is found
	Response *backend.CallResourceResponse
	// A function that should be used to cache a CallResourceResponse for a given resource request.
	// It can be set to nil by the method implementation (if there is an error, for example), so it should be checked before being called.
	// Because plugins can send multiple responses asynchronously, the implementation should be able to handle multiple calls to this function for one request.
	UpdateCacheFn CacheResourceResponseFn
}

type CachingService

type CachingService interface {
	// HandleQueryRequest uses a QueryDataRequest to check the cache for any existing results for that query.
	// If none are found, it should return false and a CachedQueryDataResponse with an UpdateCacheFn which can be used to update the results cache after the fact.
	// This function may populate any response headers (accessible through the context) with the cache status using the X-Cache header.
	HandleQueryRequest(context.Context, *backend.QueryDataRequest) (bool, CachedQueryDataResponse)
	// HandleResourceRequest uses a CallResourceRequest to check the cache for any existing results for that request. If none are found, it should return false.
	// This function may populate any response headers (accessible through the context) with the cache status using the X-Cache header.
	HandleResourceRequest(context.Context, *backend.CallResourceRequest) (bool, CachedResourceDataResponse)
}

type FakeOSSCachingService

type FakeOSSCachingService struct {
	ReturnHit              bool
	ReturnResourceResponse CachedResourceDataResponse
	ReturnQueryResponse    CachedQueryDataResponse
	// contains filtered or unexported fields
}

func NewFakeOSSCachingService

func NewFakeOSSCachingService() *FakeOSSCachingService

func (*FakeOSSCachingService) AssertCalls

func (f *FakeOSSCachingService) AssertCalls(t *testing.T, fn string, times int)

func (*FakeOSSCachingService) HandleQueryRequest

func (*FakeOSSCachingService) HandleResourceRequest

func (*FakeOSSCachingService) Reset

func (f *FakeOSSCachingService) Reset()

type OSSCachingService

type OSSCachingService struct {
}

Implementation of interface - does nothing

func ProvideCachingService

func ProvideCachingService() *OSSCachingService

func (*OSSCachingService) HandleQueryRequest

func (*OSSCachingService) HandleResourceRequest

Jump to

Keyboard shortcuts

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