requestcache

package module
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 12 Imported by: 3

README

requestcache

A library of caches for on-demand generated content.

Documentation is at http://godoc.org/github.com/ctessum/requestcache.

Documentation

Overview

Package requestcache provides functions for caching on-demand generated data.

Index

Constants

This section is empty.

Variables

View Source
var FileExtension = ".dat"

FileExtension is appended to request key names to make up the names of files being written to disk.

Functions

This section is empty.

Types

type Cache

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

Cache is a holder for one or multiple caches.

func NewCache

func NewCache(cachefuncs ...CacheFunc) *Cache

NewCache creates a new set of caches for on-demand generated content, where cachefuncs specifies the caches to be used, listed in order of priority.

func (*Cache) NewRequest

func (c *Cache) NewRequest(ctx context.Context, job Job) *Request

NewRequest creates a new request where job is the job to be run. The request is not sent to the queue until the Result method is called.

func (*Cache) NewRequestRecursive

func (c *Cache) NewRequestRecursive(ctx context.Context, job JobRecursive) *Request

NewRequestRecursive creates a new request where job is the job to be run. The request is not sent to the queue until the Result method is called.

func (*Cache) Requests

func (c *Cache) Requests() []int

Requests returns the number of requests that each cache has received. The last index in the output is the number of requests received by the processor. So, for example, the miss rate for the first cache in c is r[len(r)-1] / r[0], where r is the result of this function.

type CacheFunc

type CacheFunc func(in chan *Request) (out chan *Request)

A CacheFunc can be used to store request results in a cache.

func Deduplicate

func Deduplicate() CacheFunc

Deduplicate avoids duplicating requests.

func Disk

func Disk(dir string) CacheFunc

Disk manages an on-disk cache of results, where dir is the directory in which to store results.

func GoogleCloudStorage

func GoogleCloudStorage(ctx context.Context, bucket, subdir string) (CacheFunc, error)

GoogleCloudStorage manages an cache of results in Google Cloud Storage, where bucket is the bucket in which to store results and subdir is the bucket subdirectory, if any, that should be used.

func HTTP

func HTTP(addr string) CacheFunc

HTTP retrieves cached requests over an HTTP connection, where addr is the address where results are stored. This function does not cache requests, it only retrieves previously cached requests.

func Memory

func Memory(maxEntries int) CacheFunc

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) (CacheFunc, error)

SQL manages a cache of results in an SQL database, where db is the database connection.

type Job

type Job interface {
	// Run runs the job and fills the provided result.
	Run(context.Context, Result) error

	// Key returns a unique identifier for this job.
	Key() string
}

A Job specifies a unit of work to be run and cached with a unique key.

type JobRecursive

type JobRecursive interface {
	// Run runs the job and fills the provided result.
	Run(context.Context, *Cache, Result) error

	// Key returns a unique identifier for this job.
	Key() string
}

A JobRecursive specifies a unit of work to be run and cached with a unique key, which may include recursive requests for other jobs.

type Request

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

Request holds information about a request that is to be handled either by a cache or a ProcessFunc.

func (*Request) Result

func (r *Request) Result(result Result) error

Result sends the request for processing and fills the provided result variable.

type Result

Result specifies the properties of items that can be used to extract results.

Jump to

Keyboard shortcuts

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