cache

package
v0.0.0-...-84d4900 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package cache is a midware thats stores one signature, composed of fields with information about the document that is accessed, with that signature one document is identified and the validit of it is considered for the sacke of cache.

Index

Constants

View Source
const ErrNoStats = "no stat for file %v"

ErrNoStats - error for the file thant hanven't stat information.

Variables

This section is empty.

Functions

func Cache

func Cache(expire time.Duration, cs *Storage, meta Meta, f http.HandlerFunc) http.HandlerFunc

Cache handler check with version do to the user, cached or a new one. Cache sets too the header cache specific values.

Types

type Document

type Document interface {
	OutDate(cached Document) bool
	Name() string
	Path() string
	Modification() time.Time
	RootDirHash() string
	New(m time.Time) Document
	Sulfix() string
}

Document interface give access to cache control functions for the documents struct.

type Image

type Image struct {
	FileName  string
	MTime     time.Time
	Lang      string
	Mime      string
	UserAgent string
	//ResponseCode string
	Hash      string
	Width     int
	Height    int
	Extension string
}

Image represents the metadata, cache relevant information. The local version.

func (*Image) ComposeFileName

func (i *Image) ComposeFileName(r *http.Request)

ComposeFileName creates the file name from the data find in the request.

func (*Image) Modification

func (i *Image) Modification() time.Time

Modification shows the time of modification of the doc.

func (*Image) Name

func (i *Image) Name() string

Name method returns the file name of the cached document.

func (*Image) New

func (i *Image) New(m time.Time) Document

New returns a new doc with the same metadata but the mtime. The new mtime will come from the cached version of the doc.

func (*Image) OutDate

func (i *Image) OutDate(cached Document) bool

OutDate tells if the cache is out of date in relation to the original image.

func (*Image) Path

func (i *Image) Path() string

Path return the full path of the cache

func (*Image) RootDirHash

func (i *Image) RootDirHash() string

RootDirHash make a hash that is used in the root dir. This root dir name will identify a group of documents with the same caracteristics.

func (*Image) Sulfix

func (i *Image) Sulfix() string

Sulfix return the sulfix of the file.

type Meta

type Meta func(r *http.Request) (Document, *http.Request, error)

Meta function collects all data about the document and put it a struct suitable to the cache handler.

func MetaFS

func MetaFS(fs afero.Fs, prefix string) Meta

MetaFS function retrives the modification time os the file being accessed.

type Storage

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

Storage is where the data is cached.

func NewStorage

func NewStorage(root string, fs afero.Fs, ttl, periode time.Duration) *Storage

NewStorage creates a new place to store que documents in cache.

func (*Storage) Close

func (s *Storage) Close()

Close terminates the gorotime associetade with this storage.

func (*Storage) GetMTime

func (s *Storage) GetMTime(d Document) (Document, error)

GetMTime retrive the mtime of document with metadata in d and return one document with the same metadata plus the mtime of the cache.

func (*Storage) ReadTo

func (s *Storage) ReadTo(d Document, w http.ResponseWriter, code int) error

ReadTo retrives documents d and write it to w.

func (*Storage) Store

func (s *Storage) Store(d Document, r io.Reader, h map[string][]string) error

Store reads from r and store under the metadata in d. h are the headers of the http ResponseWriter.

type Text

type Text struct {
	FileName  string
	MTime     time.Time
	Lang      string
	Encoding  string
	Mime      string
	UserAgent string
	// Extension must start with a dot
	Extension string
	//ResponseCode string
	// Hash the template data.
	Hash string
}

Text represents the document. The local version.

func (*Text) ComposeFileName

func (t *Text) ComposeFileName(r *http.Request)

ComposeFileName creates the file name from the data find in the request.

func (*Text) Modification

func (t *Text) Modification() time.Time

Modification shows the time of modification of the doc.

func (*Text) Name

func (t *Text) Name() string

Name method returns the file name of the cached document.

func (*Text) New

func (t *Text) New(m time.Time) Document

New returns a new doc with the same metadata but the mtime. The new mtime will come from the cached version of the doc.

func (*Text) OutDate

func (t *Text) OutDate(cached Document) bool

OutDate tells if the cache is out of date in relation to the original text.

func (*Text) Path

func (t *Text) Path() string

Path return the full path of the cache

func (*Text) RootDirHash

func (t *Text) RootDirHash() string

RootDirHash make a hash that is used in the root dir. This root dir name will identify a group of documents with the same caracteristics.

func (*Text) Sulfix

func (t *Text) Sulfix() string

Sulfix return the sulfix of the file.

Jump to

Keyboard shortcuts

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