webcache

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheNotFound = errors.New("Cache Not Found")

ErrCacheNotFound defines the error returned when the cached desired is not found.

View Source
var ErrInvalidState = errors.New("Cache Not Found")

ErrInvalidState is returned when the cache api does not exists in the global context.

View Source
var ErrRequestDoesNotExists = errors.New("Request not existing")

ErrRequestDoesNotExists is returned when the giving request does not exists in the catch.

Functions

func AllObjectToRequest

func AllObjectToRequest(o []*js.Object) []cache.Request

AllObjectToRequest returns a slice of WebResponses from a slice of js.Object.

func AllObjectToResponse

func AllObjectToResponse(o []*js.Object) []cache.Response

AllObjectToResponse returns a slice of WebResponses from a slice of js.Object.

func MapToHeaders

func MapToHeaders(res map[string]string) *js.Object

MapToHeaders converts a map into a js.Headers structure.

func ObjectToList

func ObjectToList(o *js.Object) []*js.Object

ObjectToList returns a map from a giving object.

func ObjectToMap

func ObjectToMap(o *js.Object) map[string]string

ObjectToMap returns a map from a giving object.

func ObjectToRequest

func ObjectToRequest(o *js.Object) (cache.Request, error)

ObjectToRequest converts a object to a cache.Request.

func ObjectToRequests

func ObjectToRequests(o *js.Object) []cache.Request

ObjectToRequests returns a list of cache.Request objects from the provided object.

func ObjectToResponse

func ObjectToResponse(o *js.Object) (cache.Response, error)

ObjectToResponse converts a object to a cache.Response.

func ObjectToStringList

func ObjectToStringList(o *js.Object) []string

ObjectToStringList returns a map from a giving object.

func RequestToJSRequest

func RequestToJSRequest(res *cache.Request) *js.Object

RequestToJSRequest converts a object to a js.Request.

func ResponseToJSResponse

func ResponseToJSResponse(res *cache.Response) *js.Object

ResponseToJSResponse converts a object to a js.Response.

Types

type CacheAPI

type CacheAPI struct {
	*js.Object
}

CacheAPI defines individual cache item received from a call to the internal cache API.

func New

func New(cacheName string) (*CacheAPI, error)

New returns a new instance of the CacheAPI using the browsers cache API. API found in webkit browsers. https://developer.mozilla.org/en-US/docs/Web/API/Cache.

func NewCacheAPI

func NewCacheAPI(o *js.Object) *CacheAPI

NewCacheAPI returns a new instance of the CacheAPI.

func (*CacheAPI) Add

func (c *CacheAPI) Add(request string, resp *http.Response) error

Add the giving path and response into the cache.

func (*CacheAPI) AddAll

func (c *CacheAPI) AddAll(request ...string) error

AddAll calls the internal caches.Cache.Add and caches.Cache.AddAll function matching against the request string/strings.

func (*CacheAPI) AddData

func (c *CacheAPI) AddData(path string, data []byte) error

AddData adds the giving data object into the cache.

func (*CacheAPI) All

func (c *CacheAPI) All() ([]cache.WebPair, error)

All returns all the pairs of requests which have been added into the cache in the order they were added.

func (*CacheAPI) Delete

func (c *CacheAPI) Delete(request string) error

Delete calls the underline CacheAPI.DeleteRequest.

func (*CacheAPI) DeletePath

func (c *CacheAPI) DeletePath(request string, attr map[string]interface{}) error

DeletePath deletes the given path from the cache if found.

func (*CacheAPI) DeleteRequest

func (c *CacheAPI) DeleteRequest(request cache.Request, attr map[string]interface{}) error

DeleteRequest calls the internal caches.Cache.Delete function matching against the request for a js.Cache.Delete.

func (*CacheAPI) Empty

func (c *CacheAPI) Empty() error

Empty deletes all giving requests from the underline cache.

func (*CacheAPI) Get

func (c *CacheAPI) Get(request string) (cache.Request, cache.Response, error)

Get calls CacheAPI.MatchPath and passing in a default MatchAttr value.

func (*CacheAPI) Keys

func (c *CacheAPI) Keys(request interface{}, attr map[string]interface{}) ([]cache.Request, error)

Keys returns a slice of all cache keys for all request added in the order they were added.

func (*CacheAPI) Match

func (c *CacheAPI) Match(request cache.Request, attr map[string]interface{}) (cache.Response, error)

Match calls the internal caches.Cache.Match function matching against the request string for a js.Cache.Match.

func (*CacheAPI) MatchAll

func (c *CacheAPI) MatchAll(request cache.Request, attr map[string]interface{}) ([]cache.Response, error)

MatchAll calls the internal caches.Cache.MatchAll function matching against the request string for a js.Cache.Match.

func (*CacheAPI) MatchAllPath

func (c *CacheAPI) MatchAllPath(request string, attr map[string]interface{}) ([]cache.Response, error)

MatchAllPath calls the internal caches.Cache.MatchAll function matching against the request string for a js.Cache.Match.

func (*CacheAPI) MatchPath

func (c *CacheAPI) MatchPath(request string, attr map[string]interface{}) (cache.Response, error)

MatchPath calls the internal caches.Cache.Match function matching against the request string.

func (*CacheAPI) Put

func (c *CacheAPI) Put(request cache.Request, res cache.Response) error

Put calls the internal caches.Cache.Put function matching against the request string.

func (*CacheAPI) Serve

func (c *CacheAPI) Serve(w http.ResponseWriter, r *http.Request) error

Serve attempts to find the request and serve the response into the provided http.ResponseWriter.

Jump to

Keyboard shortcuts

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