httpcache: Index | Files

package server

import ""


Package Files

server.go store.go

func New Uses

func New(addr string, store Store) *http.Server

New returns a http.Server which hosts the server-side handler for the remote cache service.

it doesn't listens to the server

type Handler Uses

type Handler struct {
    // contains filtered or unexported fields

Handler is the remote cache service's Handler (a simple http server using this handler is the server side ) keeps the cache entries, this time based on keys these keys are the request's full encoded url more than one clients(other http servers) can call(via http rest api) this handler.

one handler per cache service yes, you're able to have more than one cache service in the same http server

func (*Handler) ServeHTTP Uses

func (s *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the cache Service to the outside world, it is used only when you want to achieve something like horizontal scaling it parses the request and tries to return the response with the cached body of the requested cache key server-side function

type Store Uses

type Store interface {
    // Set adds an entry to the cache by its key
    // entry must contain a valid status code, conten type, a body and optional, the expiration duration
    Set(key string, statusCode int, contentType string, body []byte, expiration time.Duration)
    // Get returns an entry based on its key
    Get(key string) *entry.Entry
    // Remove removes a cache entry for the cache
    // a Set action is needed to re-enable this entry
    // it is used only on manually invalidate cache
    // otherwise a silent update to the underline entry's
    // Response is done
    Remove(key string)

Store is the interface of the cache bug, default is memory store for performance reasons

func NewMemoryStore Uses

func NewMemoryStore() Store

NewMemoryStore returns a new memory store for the cache , note that httpcache package provides one global default cache service which provides these functions: `httpcache.Cache`, `httpcache.Invalidate` and `httpcache.Start`

If you use only one global cache for all of your routes use the `httpcache.New` instead

Package server imports 8 packages (graph). Updated 2017-04-12. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).