Documentation ¶
Overview ¶
Package requestcache provides functions for caching on-demand generated data.
Index ¶
- Variables
- func MarshalGob(data interface{}) ([]byte, error)
- func UnmarshalGob(b []byte) (interface{}, error)
- type Cache
- type CacheFunc
- func Deduplicate() CacheFunc
- func Disk(dir string, marshalFunc func(interface{}) ([]byte, error), ...) CacheFunc
- func GoogleCloudStorage(ctx context.Context, bucket, subdir string, ...) (CacheFunc, error)
- func HTTP(addr string, unmarshalFunc func([]byte) (interface{}, error)) CacheFunc
- func Memory(maxEntries int) CacheFunc
- func SQL(ctx context.Context, db *sql.DB, marshalFunc func(interface{}) ([]byte, error), ...) (CacheFunc, error)
- type ProcessFunc
- type Request
Constants ¶
This section is empty.
Variables ¶
var FileExtension = ".dat"
FileExtension is appended to request key names to make up the names of files being written to disk.
Functions ¶
func MarshalGob ¶
MarshalGob marshals an interface to a byte array and fulfills the requirements for the Disk cache marshalFunc input.
func UnmarshalGob ¶
UnmarshalGob unmarshals an interface from a byte array and fulfills the requirements for the Disk cache unmarshalFunc input.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a holder for one or multiple caches.
func NewCache ¶
func NewCache(processor ProcessFunc, numProcessors int, cachefuncs ...CacheFunc) *Cache
NewCache creates a new set of caches for on-demand generated content, where processor is the function that creates the content, numProcessors is the number of processors that will be working in parallel, and cachefuncs are the caches to be used, listed in order of priority.
func (*Cache) NewRequest ¶
NewRequest creates a new request where requestPayload is the input data that will be used to generate the results and key is a unique key.
type CacheFunc ¶
A CacheFunc can be used to store request results in a cache.
func Disk ¶
func Disk(dir string, marshalFunc func(interface{}) ([]byte, error), unmarshalFunc func([]byte) (interface{}, error)) CacheFunc
Disk manages an on-disk cache of results, where dir is the directory in which to store results, marshalFunc is the function to be used to marshal the data object to binary form, and unmarshalFunc is the function to be used to unmarshal the data from binary form.
func GoogleCloudStorage ¶
func GoogleCloudStorage(ctx context.Context, bucket, subdir string, marshalFunc func(interface{}) ([]byte, error), unmarshalFunc func([]byte) (interface{}, error)) (CacheFunc, error)
GoogleCloudStorage manages an cache of results in Google Cloud Storage, where bucket is the bucket in which to store results, subdir is the bucket subdirectory, if any, that should be used, marshalFunc is the function to be used to marshal the data object to binary form, and unmarshalFunc is the function to be used to unmarshal the data from binary form.
func HTTP ¶
HTTP retrieves cached requests over an HTTP connection, where addr is the address where results are stored and unmarshalFunc is the function to be used to unmarshal the data from binary form. This function does not cache requests, it only retrieves previously cached requests.
func Memory ¶
Memory manages an in-memory cache of results, where maxEntries is the max number of items in the cache. If the results returned by this cache are modified by the caller, they may also be modified in the cache.
func SQL ¶
func SQL(ctx context.Context, db *sql.DB, marshalFunc func(interface{}) ([]byte, error), unmarshalFunc func([]byte) (interface{}, error)) (CacheFunc, error)
SQL manages a cache of results in an SQL database, where db is the database connection, marshalFunc is the function to be used to marshal the data object to binary form, and unmarshalFunc is the function to be used to unmarshal the data from binary form.
type ProcessFunc ¶
type ProcessFunc func(ctx context.Context, requestPayload interface{}) (resultPayload interface{}, err error)
ProcessFunc defines the format of functions that can be used to process a request payload and return a resultPayload.