Documentation ¶
Index ¶
- Variables
- type Cache
- type Client
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Get(url string) (resp *http.Response, err error)
- func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
- func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)
- type Handler
- type HttpResponseObject
- type MemoryCache
- type Object
- type StorageCache
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Always use the latest. NewLatestHandler = func() *Handler { return &Handler{ Pre: func(c Cache, o Object) (io.Reader, error) { return nil, nil }, Post: func(c Cache, o Object) error { return c.Put(o) }, } } // Get the latest only once at the beginning. NewOnceLatestHandler = func() *Handler { var hander Handler hander.keys = make([]string, 0, 1000) hander.Pre = func(c Cache, o Object) (io.Reader, error) { hander.mu.Lock() defer hander.mu.Unlock() if slices.Contains(hander.keys, o.Key()) { return c.Query(o) } return nil, nil } hander.Post = func(c Cache, o Object) error { hander.mu.Lock() defer hander.mu.Unlock() if slices.Contains(hander.keys, o.Key()) { return nil } hander.keys = append(hander.keys, o.Key()) return c.Put(o) } return &hander } // If there is a cache, use it; if not, get the latest and save the cache. NewDefaultHandler = func() *Handler { var hander Handler hander.keys = make([]string, 0, 1000) hander.Pre = func(c Cache, o Object) (io.Reader, error) { hander.mu.Lock() defer hander.mu.Unlock() r, err := c.Query(o) if err != nil { return r, err } hander.keys = append(hander.keys, o.Key()) return r, nil } hander.Post = func(c Cache, o Object) error { hander.mu.Lock() defer hander.mu.Unlock() if slices.Contains(hander.keys, o.Key()) { return nil } return c.Put(o) } return &hander } // Always use and save cache. NewSimpleHandler = func() *Handler { var hander Handler hander.Pre = func(c Cache, o Object) (io.Reader, error) { return c.Query(o) } hander.Post = func(c Cache, o Object) error { return c.Put(o) } return &hander } )
View Source
var DefaultClient = &Client{ Client: http.DefaultClient, Cache: DefaultStorageCache, Handler: NewDefaultHandler(), }
View Source
var DefaultMemoryCache = &MemoryCache{}
View Source
var DefaultStorageCache = &StorageCache{}
View Source
var ErrNoCache = errors.New("no cache")
Functions ¶
This section is empty.
Types ¶
type HttpResponseObject ¶
type HttpResponseObject struct {
// contains filtered or unexported fields
}
func NewHttpResponseObject ¶
func NewHttpResponseObject(uri string) (*HttpResponseObject, error)
func (*HttpResponseObject) Key ¶
func (o *HttpResponseObject) Key() string
func (*HttpResponseObject) Length ¶
func (o *HttpResponseObject) Length() int64
func (*HttpResponseObject) NewReader ¶
func (o *HttpResponseObject) NewReader() io.Reader
func (*HttpResponseObject) ReadResponse ¶
func (o *HttpResponseObject) ReadResponse(resp *http.Response) error
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
func (*MemoryCache) Put ¶
func (c *MemoryCache) Put(o Object) error
type StorageCache ¶
type StorageCache struct {
// contains filtered or unexported fields
}
func NewStorageCache ¶
func NewStorageCache(dir string) *StorageCache
func (*StorageCache) Put ¶
func (c *StorageCache) Put(o Object) error
Click to show internal directories.
Click to hide internal directories.