entry

package
v10.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 {
	// 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, contentType 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) ContentType

func (r *Response) ContentType() string

ContentType returns a valid content type

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