cache

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 13 Imported by: 1

README

cache

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheFileExpired = errors.New("Cache file expired")
View Source
var NotJSONData = errors.New("data is not json formatted")

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(store CacheStore, client HTTPClient) *Cache

func (*Cache) CacheFunc

func (c *Cache) CacheFunc(f func() ([]byte, error), name string, cacheTime time.Duration) ([]byte, error)

CacheFunc checks if the file cacheFile exists and is less than cacheTime old. If so, it returns the contents of cacheFile. Otherwise, it executes the function f and, if no error is returned, writes the output to cacheFile and returns the result.

func (*Cache) CacheFuncJSON

func (c *Cache) CacheFuncJSON(f func(interface{}) error, obj interface{}, name string, cacheTime time.Duration) error

func (*Cache) CacheRequest

func (c *Cache) CacheRequest(req *http.Request, cacheTime time.Duration) (*http.Response, error)

func (*Cache) CacheRequestData

func (c *Cache) CacheRequestData(req *http.Request, cacheTime time.Duration) ([]byte, error)

func (*Cache) CacheRequestJSON

func (c *Cache) CacheRequestJSON(req *http.Request, obj interface{}, cacheTime time.Duration) error

func (*Cache) CacheURL

func (c *Cache) CacheURL(u string, cacheTime time.Duration) (*http.Response, error)

func (*Cache) CacheURLData

func (c *Cache) CacheURLData(u string, cacheTime time.Duration) ([]byte, error)

func (*Cache) CacheURLJSON

func (c *Cache) CacheURLJSON(u string, obj interface{}, cacheTime time.Duration) error

type CacheFile

type CacheFile interface {
	Read([]byte) (int, error)
	Write([]byte) (int, error)
	Close() error
	Valid() bool
}

type CacheStore

type CacheStore interface {
	Open(string, time.Duration) (CacheFile, error)
	Delete(string) error
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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