entry

package
v10.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyHeaders

func CopyHeaders(dst map[string][]string, src map[string][]string)

CopyHeaders clones headers "src" to "dst" .

func ParseMaxAge

func ParseMaxAge(header string) int64

ParseMaxAge parses the max age from the receiver parameter, "cache-control" header returns seconds as int64 if header not found or parse failed then it returns -1

Types

type Entry

type Entry struct {

	// when `Reset` this value is reseting to time.Now(),
	// it's used to send the "Last-Modified" header,
	// some clients may need it.
	LastModified time.Time
	// contains filtered or unexported fields
}

Entry is the cache entry contains the expiration datetime and the response

func NewEntry

func NewEntry(duration time.Duration) *Entry

NewEntry returns a new cache entry it doesn't sets the expiresAt & the response because these are setting each time on Reset

func (*Entry) ChangeLifetime

func (e *Entry) ChangeLifetime(fdur LifeChanger)

ChangeLifetime modifies the life field which is the life duration of the cached response of this cache entry

useful when we find a max-age header from the handler

func (*Entry) Reset

func (e *Entry) Reset(statusCode int, headers map[string][]string,
	body []byte, lifeChanger LifeChanger)

Reset called each time the entry is expired and the handler calls this after the original handler executed to re-set the response with the new handler's content result

func (*Entry) Response

func (e *Entry) Response() (*Response, bool)

Response gets the cache response contents if it's valid returns them with a true value otherwise returns nil, false

type LifeChanger

type LifeChanger func() time.Duration

LifeChanger is the function which returns a duration which will be compared with the current entry's (cache life) duration and execute the LifeChanger func to set the new life time

type Response

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

Response is the cached response will be send to the clients its fields setted at runtime on each of the non-cached executions non-cached executions = first execution, and each time after cache expiration datetime passed.

func (*Response) Body

func (r *Response) Body() []byte

Body returns contents will be served by the cache handler.

func (*Response) Headers

func (r *Response) Headers() http.Header

Headers returns the total headers of the cached response.

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns a valid status code.

Jump to

Keyboard shortcuts

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