proxy

package
v0.0.0-...-d95a202 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2014 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.Mutex

	Stats Stats
	// contains filtered or unexported fields
}

A cache

func NewCache

func NewCache(size int, ttl time.Duration, refreshChance float32) *Cache

Creates a cache

func (*Cache) Clear

func (c *Cache) Clear()

Clears the cache

func (*Cache) Get

func (c *Cache) Get(key string, refresh RefreshFn) (interface{}, error)

Fetches something from the cache. If not found, refresh() will be called

func (*Cache) Set

func (c *Cache) Set(key string, v interface{})

Adds something to the cache

type CacheEntry

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

A cache Entry

type Config

type Config struct {
	// Cache size
	CacheSize int
	// TTL
	// Cache is asynchronous during the TTL duration after an update.
	TTL time.Duration
	// API Master ref refresh frequency
	// The proxy will check at this interval if something has changed.
	MasterRefresh time.Duration
	// Base refresh chance after a master reference update, between 0 and 1
	BaselineRefreshChance float32
	// contains filtered or unexported fields
}

type Proxy

type Proxy struct {
	Config Config
	// contains filtered or unexported fields
}

func New

func New(u, accessToken string, apiCfg goprismic.Config, cfg Config) (*Proxy, error)

Creates a proxy

All documents are cached in a LRU cache of cacheSize elements.

func (*Proxy) Clear

func (p *Proxy) Clear()

Clears the cache

func (*Proxy) Direct

func (p *Proxy) Direct() *goprismic.Api

Queries the API

proxy.Direct().Master().Form("everything").Submit()

func (*Proxy) Get

func (p *Proxy) Get(key string, refresh RefreshFn) (interface{}, error)

Get something from the proxy

func (*Proxy) GetDocument

func (p *Proxy) GetDocument(id string) (*goprismic.Document, error)

Fetches a document by id

func (*Proxy) GetDocumentBy

func (p *Proxy) GetDocumentBy(docType, field string, value interface{}) (*goprismic.Document, error)

Fetches a document of a specific type by a field value

func (*Proxy) GetStats

func (p *Proxy) GetStats() Stats

Returns the cache stats

func (*Proxy) Refresh

func (p *Proxy) Refresh() bool

Refreshes the master ref, returns true if master ref has changed

func (*Proxy) Search

func (p *Proxy) Search() *SearchForm

Search documents

type RefreshFn

type RefreshFn func() (interface{}, error)

type SearchForm

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

func (*SearchForm) Data

func (s *SearchForm) Data(data map[string]string) *SearchForm

Adds form data

func (*SearchForm) Error

func (s *SearchForm) Error() error

Returns the error

func (*SearchForm) Form

func (s *SearchForm) Form(name string) *SearchForm

Selects the form on which to use

func (*SearchForm) Order

func (s *SearchForm) Order(field string, order int) *SearchForm

Order result - can be chained multiple times

example : form.Order("my.product.name", OrderAsc).Order("my.product.size", OrderDesc)

func (*SearchForm) Page

func (s *SearchForm) Page(page int) *SearchForm

Sets the page number

func (*SearchForm) PageSize

func (s *SearchForm) PageSize(pageSize int) *SearchForm

Sets the page size

func (*SearchForm) Query

func (s *SearchForm) Query(query string) *SearchForm

Query the form using a predicate query ([[:d = any(document.type, ["article"])]])

func (*SearchForm) Submit

func (s *SearchForm) Submit() (*goprismic.SearchResult, error)

Searches the repository If search fails, it might mean that the master revision has changed

type Stats

type Stats struct {
	Get          int
	Hit          int
	Miss         int
	Refresh      int
	RefreshError int
	Eviction     int
	Error        int
}

Jump to

Keyboard shortcuts

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