driver

package
v0.0.0-...-576eb72 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package driver includes the interfaces required to implement a Gondola cache driver, as well as the dummy, memory and file drivers.

Additionally, drivers with no external dependencies are provided by this package. Note that Gondola already imports this package, so users don't need to explicitely import it.

The provided drivers are:

  • dummy:// - a dummy driver which does not cache data, useful for development
  • memory://[#max_size={size} - a memory driver with an optional maximum size
  • file://path[#max_size={size} a file based driver with an optional maximum size

Sizes admit the K, M, G and T suffixes to represent Kilobytes, Megabytes, Gigabytes and Terabytes, respectivelly. When there's no prefix, the value is assumed to be in bytes. Note that real numbers can be used, like e.g. 1.5G

Paths which don't start with a / are interepreted as relative to the application binary (using gnd.la/util/pathutil.Relative), while paths starting by / are interpreted as absolute. Note that paths should aways use forward slashes, even in platforms which use the backslash by default (e.g. /C:/Documents/my_cache_path).

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotImplemented can be used by drivers to signal
	// the cache that they don't implement a given feature.
	ErrNotImplemented = errors.New("not implemented")
)

Functions

func DefaultPort

func DefaultPort(addr string, port int) string

DefaultPort adds port to the addr passed in if it doesn't already have a port. It works for hostnames, IPv4 and IPv6 addresses. In case addr is empty, localhost:port is returned.

func Register

func Register(name string, f Opener)

Register registers a new cache driver with the given protocol and opener function. This function is not thread safe, as it's only intended to be used from the main goroutine.

Types

type Driver

type Driver interface {
	// Set sets the cached value to the given []byte. Drivers should
	// interpret timeout as the number of seconds until the item
	// expires, with zero meaning no expiration.
	Set(key string, b []byte, timeout int) error
	// Get returns the []byte assocciated with the given key. If the
	// key is not found, no error should be returned. A nil []byte
	// with no error should be returned instead.
	Get(key string) ([]byte, error)
	// GetMulti returns the values for the given keys (if present) as a map.
	// The returned map should not include keys for keys not found in the cache.
	// As in Get(), an error should be returned only if there was an error when
	// communicating with the cache, not if no items (or just some items) were found.
	GetMulti(keys []string) (map[string][]byte, error)
	// Delete removes the given key from the cache. Drivers shouldn't
	// return an error if the key doesn't exists, only if there was
	// an error while deleting it.
	Delete(key string) error
	// Close closes the connection with the cache
	// backend.
	Close() error
	// Connection returns the underlying connection
	// to the cache, which is driver dependant and
	// might even be nil.
	Connection() interface{}
	// Flush clears the cache, removing all cached items.
	Flush() error
}

Driver is the interface implemented by cache drivers.

type DummyDriver

type DummyDriver struct {
}

DummyDriver implements a dummy cache, which doesn't store any information and never returns an object.

func (*DummyDriver) Close

func (d *DummyDriver) Close() error

func (*DummyDriver) Connection

func (d *DummyDriver) Connection() interface{}

func (*DummyDriver) Delete

func (d *DummyDriver) Delete(key string) error

func (*DummyDriver) Flush

func (d *DummyDriver) Flush() error

func (*DummyDriver) Get

func (d *DummyDriver) Get(key string) ([]byte, error)

func (*DummyDriver) GetMulti

func (d *DummyDriver) GetMulti(keys []string) (map[string][]byte, error)

func (*DummyDriver) Set

func (d *DummyDriver) Set(key string, b []byte, timeout int) error

type FileSystemDriver

type FileSystemDriver struct {
	Root string
}

func (*FileSystemDriver) Close

func (f *FileSystemDriver) Close() error

func (*FileSystemDriver) Connection

func (f *FileSystemDriver) Connection() interface{}

func (*FileSystemDriver) Delete

func (f *FileSystemDriver) Delete(key string) error

func (*FileSystemDriver) Flush

func (f *FileSystemDriver) Flush() error

func (*FileSystemDriver) Get

func (f *FileSystemDriver) Get(key string) ([]byte, error)

func (*FileSystemDriver) GetMulti

func (f *FileSystemDriver) GetMulti(keys []string) (map[string][]byte, error)

func (*FileSystemDriver) Set

func (f *FileSystemDriver) Set(key string, b []byte, timeout int) error

type MemoryDriver

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

func (*MemoryDriver) Close

func (d *MemoryDriver) Close() error

func (*MemoryDriver) Connection

func (d *MemoryDriver) Connection() interface{}

func (*MemoryDriver) Delete

func (d *MemoryDriver) Delete(key string) error

func (*MemoryDriver) Flush

func (d *MemoryDriver) Flush() error

func (*MemoryDriver) Get

func (d *MemoryDriver) Get(key string) ([]byte, error)

func (*MemoryDriver) GetMulti

func (d *MemoryDriver) GetMulti(keys []string) (map[string][]byte, error)

func (*MemoryDriver) Set

func (d *MemoryDriver) Set(key string, b []byte, timeout int) error

type Opener

type Opener func(url *config.URL) (Driver, error)

Opener is a function which returns a new Driver connection with the given driver-dependent value and the given options Some options are used by cache system and are documented in the Gondola's cache package, while others are driver dependent and are documented in each driver. Drivers should just ignore options which they don't use.

func Get

func Get(name string) Opener

Get returns the opener function for the driver with the given name, or nil if there's no such driver.

Directories

Path Synopsis
Package memcache implements a Gondola cache driver using memcache.
Package memcache implements a Gondola cache driver using memcache.
Package redis implements a Gondola cache driver using redis.
Package redis implements a Gondola cache driver using redis.

Jump to

Keyboard shortcuts

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