ccache

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const CacheItemFileExtension = ".ccache"

CacheItemFileExtension - file extension to use for

View Source
const CacheItemPrivate = "private"

CacheItemPrivate - flag, denotes cache item is private cache

View Source
const CacheItemPublic = "public"

CacheItemPublic - flag, denotes cache item is public cache

View Source
const CacheStorageFile = "file"

CacheStorageFile - storage handler name for file system handler

View Source
const CacheStorageMemory = "memory"

CacheStorageMemory - storage handler name for memory handler

View Source
const VersionNo = 1

VersionNo - current version of this extension

Variables

This section is empty.

Functions

func ExpandESI

func ExpandESI(resp *http.Response, esiTags []EsiTag, subRequestCallback func(req *http.Request) (*http.Response, error)) (*http.Response, error)

ExpandESI - take http response and replace esi tags

func HTTPResponseFromBytes

func HTTPResponseFromBytes(b []byte) (*http.Response, error)

HTTPResponseFromBytes - convert bytes to http response

func HTTPResponseToBytes

func HTTPResponseToBytes(r *http.Response) ([]byte, error)

HTTPResponseToBytes - convert http response to bytes

func PrivateKeyFromRequest

func PrivateKeyFromRequest(r *http.Request, config *Config) string

PrivateKeyFromRequest - generate private cache key from request

func PublicKeyFromRequest

func PublicKeyFromRequest(r *http.Request, config *Config) string

PublicKeyFromRequest - generate public cache key from request

func WildcardCompare

func WildcardCompare(original string, test string) bool

WildcardCompare - test if original string matches test string with wildcard

Types

type Config

type Config struct {
	CacheStorageHandlers []string                  `json:"cache_storage_handlers"` // list of cache storage handlers to use (in order)
	CacheFilePath        string                    `json:"cache_file_path"`        // file path to file system cache
	CacheMaxSize         map[string]map[string]int `json:"cache_max_size"`         // max size for each cache type (public/private) and each cache storage handler
	ResponseMaxSize      int                       `json:"response_max_size"`      // max size allowed to cache a response
	CleanInterval        int                       `json:"clean_interval"`         // interval in seconds of when to performance cache clean up`
	VaryHeaders          []string                  `json:"vary_headers"`           // headers that should be used to calculate cache keys
	InvalidateHeaders    []string                  `json:"invalidate_headers"`     // list of headers to use for cache ban/purge requests
	CachePrivate         bool                      `json:"enable_private_cache"`   // whether or not to cache private content (cache-control: private)
	VaryCookies          []string                  `json:"vary_cookies"`           // list of cookies to use to vary private cache
	UseESI               bool                      `json:"enable_esi"`             // whether or not to handle ESI tags
}

Config - cache configuration

func GetDefaultConfig

func GetDefaultConfig() Config

GetDefaultConfig - get default configuration

type EsiTag

type EsiTag struct {
	URL      string // url for ESI request
	Position int    // position in original response of ESI tag
}

EsiTag - data about ESI tag

func ParseESI

func ParseESI(resp *http.Response) (*http.Response, []EsiTag, error)

ParseESI - parse esi tags from response

type FileStorage

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

FileStorage - file system storage handler

func (*FileStorage) Delete

func (s *FileStorage) Delete() error

Delete - delete file

func (*FileStorage) FetchResponse

func (s *FileStorage) FetchResponse() (*http.Response, error)

FetchResponse - fetch response from file system

func (*FileStorage) GetSize

func (s *FileStorage) GetSize() (int64, error)

GetSize - get file size of cache item

func (*FileStorage) GetTypeName

func (s *FileStorage) GetTypeName() string

GetTypeName - get storage handler name

func (*FileStorage) Init

func (s *FileStorage) Init(key string, config *Config)

Init - init storage handler

func (*FileStorage) StoreResponse

func (s *FileStorage) StoreResponse(r *http.Response) error

StoreResponse - store http response to file system

type Handler

type Handler struct {
	Config     Config
	CacheItems []Item
	// contains filtered or unexported fields
}

Handler - main cache handler

func NewHandler

func NewHandler(config Config, subRequestCallback func(req *http.Request) (*http.Response, error)) Handler

NewHandler - create new cache handler

func (*Handler) Clean

func (b *Handler) Clean()

Clean - clean up cache items

func (*Handler) Clear

func (b *Handler) Clear()

Clear - clear all cache items

func (*Handler) Fetch

func (b *Handler) Fetch(r *http.Request) *Item

Fetch - fetch cache item from request

func (*Handler) Invalidate

func (b *Handler) Invalidate(req *http.Request)

Invalidate - remove matching items from cache

func (*Handler) OnRequest

func (b *Handler) OnRequest(req *http.Request) (*http.Response, error)

OnRequest - handle incomming request

func (*Handler) OnResponse

func (b *Handler) OnResponse(resp *http.Response) (*http.Response, error)

OnResponse - handle outgoing response

func (*Handler) Store

func (b *Handler) Store(resp *http.Response) (*Item, error)

Store - store response if cachable

type Item

type Item struct {
	Type              string
	Key               string
	Hits              int
	Size              int64
	Created           time.Time
	LastHit           time.Time
	MaxAge            int32
	Path              string
	InvalidateHeaders map[string][]string
	EsiTags           []EsiTag
	// contains filtered or unexported fields
}

Item - cached item

func ItemFromResponse

func ItemFromResponse(resp *http.Response, config *Config) (Item, error)

ItemFromResponse - create cache item from response

func (*Item) Clear

func (i *Item) Clear()

Clear - delete this cache item

func (*Item) GetResponse

func (i *Item) GetResponse() (*http.Response, error)

GetResponse - convert cache item in to http response

func (*Item) GetStorageType

func (i *Item) GetStorageType() string

GetStorageType - get storage type name

func (*Item) HasExpired

func (i *Item) HasExpired() bool

HasExpired - check if this cache item has expired

func (*Item) LogAction

func (i *Item) LogAction(action string, desc string)

LogAction - log action taken against cache item

func (*Item) MoveStorage

func (i *Item) MoveStorage(name string, config *Config) error

MoveStorage - convert current storage to given new storage

type MemoryStorage

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

MemoryStorage - memory storage handler

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete() error

Delete - delete file

func (*MemoryStorage) FetchResponse

func (s *MemoryStorage) FetchResponse() (*http.Response, error)

FetchResponse - fetch response from file system

func (*MemoryStorage) GetSize

func (s *MemoryStorage) GetSize() (int64, error)

GetSize - get file size of cache item

func (*MemoryStorage) GetTypeName

func (s *MemoryStorage) GetTypeName() string

GetTypeName - get storage handler name

func (*MemoryStorage) Init

func (s *MemoryStorage) Init(key string, config *Config)

Init - init storage handler

func (*MemoryStorage) StoreResponse

func (s *MemoryStorage) StoreResponse(r *http.Response) error

StoreResponse - store http response to file system

type Storage

type Storage interface {
	Init(key string, config *Config)
	GetTypeName() string
	StoreResponse(r *http.Response) error
	FetchResponse() (*http.Response, error)
	GetSize() (int64, error)
	Delete() error
}

Storage - define storage handler methods

func GetStorageHandler

func GetStorageHandler(name string) Storage

GetStorageHandler - get a storage handler from its name

Jump to

Keyboard shortcuts

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