webhelp.v1: gopkg.in/webhelp.v1/whcache Index | Files

package whcache

import "gopkg.in/webhelp.v1/whcache"

Package whcache provides a mechanism for per-request computation caching

Sometimes you have a helper method that performs a computation or interacts with a datastore or remote resource, and that helper method gets called repeatedly. With simple context values, since the helper method is the most descendent frame in the stack, there isn't a context specific place (besides maybe the session, which would be a bad choice) to cache context specific values. With this cache helper, there now is.

The cache must be registered up the handler chain with Register, and then helper methods can use Set/Get/Remove to interact with the cache (if available). If no cache was registered, Set/Get/Remove will still work, but Get will never return a value.

Index

Package Files

cache.go

func Get Uses

func Get(ctx context.Context, key interface{}) interface{}

Get returns previously stored key/value pairs from the context specific cache if one is registered and the value is found, and returns nil otherwise.

func Register Uses

func Register(h http.Handler) http.Handler

Register installs a cache in the handler chain.

func Remove Uses

func Remove(ctx context.Context, key interface{})

Remove removes any values stored with key from the context specific cache, if possible.

func Set Uses

func Set(ctx context.Context, key, val interface{})

Set stores the key/val pair in the context specific cache, if possible.

Package whcache imports 5 packages (graph) and is imported by 1 packages. Updated 2017-06-06. Refresh now. Tools for package owners.