cache

package
v0.0.0-...-6e49c5b Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	DeviceZip(ctx context.Context, deviceID string) (string, error)
	PutDeviceZip(ctx context.Context, deviceID, zip string) error
}

Device is a device cache which caches deviceIDs to zipcodes to prevent the constant lookup of zipcode for deviceID

type Forecast

type Forecast interface {
	GetForecast(ctx context.Context, lat, lon string) (*darksky.Forecast, error)
	PutForecast(ctx context.Context, lat, lon string, f *darksky.Forecast) error
}

Forecast is a layer which caches darksky forecast results

type Nop

type Nop struct {
}

Nop is a cache that does nothing

func (*Nop) DeviceZip

func (n *Nop) DeviceZip(ctx context.Context, deviceID string) (string, error)

func (*Nop) GetForecast

func (n *Nop) GetForecast(ctx context.Context, lat string, lon string) (*darksky.Forecast, error)

func (*Nop) GetPollen

func (n *Nop) GetPollen(ctx context.Context, zip string) (*pollen.Forecast, error)

func (*Nop) PutDeviceZip

func (n *Nop) PutDeviceZip(ctx context.Context, deviceID string, zip string) error

func (*Nop) PutForecast

func (n *Nop) PutForecast(ctx context.Context, lat string, lon string, f *darksky.Forecast) error

func (*Nop) PutPollen

func (n *Nop) PutPollen(ctx context.Context, zip string, p *pollen.Forecast) error

type Pollen

type Pollen interface {
	GetPollen(ctx context.Context, zipcode string) (*pollen.Forecast, error)
	PutPollen(ctx context.Context, zipcode string, p *pollen.Forecast) error
}

Pollen is a layer which caches pollen count information

type Redis

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

Redis is a cache that uses redis

func NewRedis

func NewRedis(pool RedisPool) *Redis

NewRedis creates a new redis cache store with the default TTL of 15m

func (*Redis) DeviceZip

func (c *Redis) DeviceZip(ctx context.Context, deviceID string) (string, error)

DeviceZip retrieves a zipcode for a deviceID

func (*Redis) GetForecast

func (c *Redis) GetForecast(ctx context.Context, lat, lon string) (*darksky.Forecast, error)

GetForecast retrieves a cache forecast from the redis store. If no cache exists then nil, nil is returned.

func (*Redis) GetPollen

func (c *Redis) GetPollen(ctx context.Context, zip string) (*pollen.Forecast, error)

GetPollen retrieves a cache forecast from the redis store. If no cache exists then nil, nil is returned.

func (*Redis) PutDeviceZip

func (c *Redis) PutDeviceZip(ctx context.Context, deviceID, zip string) error

PutDeviceZip stores a zipcode for a deviceID

func (*Redis) PutForecast

func (c *Redis) PutForecast(ctx context.Context, lat, lon string, f *darksky.Forecast) error

PutForecast stores a forecast to the redis store

func (*Redis) PutPollen

func (c *Redis) PutPollen(ctx context.Context, zip string, f *pollen.Forecast) error

PutPollen stores a forecast to the redis store

func (*Redis) SetTTL

func (c *Redis) SetTTL(dur time.Duration)

SetTTL sets the TTL used for every cache record in Redis

type RedisPool

type RedisPool interface {
	Get() redis.Conn
}

RedisPool is a pool of redis connections

type WriteThroughDevice

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

WriteThroughDevice is a cache layer that has a fallback layer

func NewWriteThroughDevice

func NewWriteThroughDevice(cache Device, api alexa.API) *WriteThroughDevice

NewWriteThroughDevice creates a new WriteThrough cache

func (*WriteThroughDevice) DeviceZip

func (w *WriteThroughDevice) DeviceZip(ctx context.Context, accessToken, deviceID string) (string, error)

DeviceZip first tries to retrieve a cached result and falls back to directly fetching to the API. If the API is used then results are stored in the cache store

type WriteThroughForecast

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

WriteThroughForecast is a cache layer that has a fallback layer

func NewWriteThroughForecast

func NewWriteThroughForecast(cache Forecast, api *darksky.API) *WriteThroughForecast

NewWriteThroughForecast creates a new WriteThrough cache

func (*WriteThroughForecast) GetForecast

func (w *WriteThroughForecast) GetForecast(ctx context.Context, lat, lon string) (*darksky.Forecast, error)

GetForecast first tries to retrieve a cached result and falls back to directly fetching to the API. If the API is used then results are stored in the cache store

type WriteThroughPollen

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

WriteThroughPollen is a cache layer that has a fallback layer

func NewWriteThroughPollen

func NewWriteThroughPollen(cache Pollen, api *pollen.API) *WriteThroughPollen

NewWriteThroughPollen creates a new WriteThrough cache

func (*WriteThroughPollen) GetPollen

func (w *WriteThroughPollen) GetPollen(ctx context.Context, loc *tz.Location) (*pollen.Forecast, error)

GetPollen first tries to retrieve a cached result and falls back to directly fetching to the API. If the API is used then results are stored in the cache store

Jump to

Keyboard shortcuts

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