cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cache defines the ResourceCache interface and provides the most basic implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResourceCache

type ResourceCache interface {
	// Lookup returns a Resource matching req. It returns nil (with no error)
	// when ResourceCache contains no matching Resource.
	Lookup(req *http.Request) (*resource.Resource, error)

	// Store stores the provided Resource r into the cache.
	Store(r *resource.Resource) error
}

ResourceCache caches resource.Resources.

ResourceCache implementations should match Resources in a way analogous to HTTP caches: the returned Resource should have a matching RequestURL and, if applicable, compatible HTTP Variants headers (but see Bugs with OnMemoryCache).

For HTTP Variants, please see: https://httpwg.org/http-extensions/draft-ietf-httpbis-variants.html.

func NewBoundedInMemoryCache

func NewBoundedInMemoryCache(size int) ResourceCache

NewBoundedInMemoryCache returns a new ResourceCache that stores Resources in memory, with an eviction policy after `size` entries. size must be positive.

func NewOnMemoryCache

func NewOnMemoryCache() ResourceCache

NewOnMemoryCache creates and initializes a new ResourceCache storing Resources on memory.

func NilCache

func NilCache() ResourceCache

NilCache returns a ResourceCache that stores and retrieves nothing.

Notes

Bugs

  • OnMemoryCache uses only RequestURL for the cache key at this moment; it is not aware of Vary or Variants yet.

Directories

Path Synopsis
Package filewrite provides ResourceCache that also saves signed exchanges to files on the Store operations to the cache.
Package filewrite provides ResourceCache that also saves signed exchanges to files on the Store operations to the cache.

Jump to

Keyboard shortcuts

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