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 ¶
- Variables
- func DefaultPort(addr string, port int) string
- func Register(name string, f Opener)
- type Driver
- type DummyDriver
- func (d *DummyDriver) Close() error
- func (d *DummyDriver) Connection() interface{}
- func (d *DummyDriver) Delete(key string) error
- func (d *DummyDriver) Flush() error
- func (d *DummyDriver) Get(key string) ([]byte, error)
- func (d *DummyDriver) GetMulti(keys []string) (map[string][]byte, error)
- func (d *DummyDriver) Set(key string, b []byte, timeout int) error
- type FileSystemDriver
- func (f *FileSystemDriver) Close() error
- func (f *FileSystemDriver) Connection() interface{}
- func (f *FileSystemDriver) Delete(key string) error
- func (f *FileSystemDriver) Flush() error
- func (f *FileSystemDriver) Get(key string) ([]byte, error)
- func (f *FileSystemDriver) GetMulti(keys []string) (map[string][]byte, error)
- func (f *FileSystemDriver) Set(key string, b []byte, timeout int) error
- type MemoryDriver
- func (d *MemoryDriver) Close() error
- func (d *MemoryDriver) Connection() interface{}
- func (d *MemoryDriver) Delete(key string) error
- func (d *MemoryDriver) Flush() error
- func (d *MemoryDriver) Get(key string) ([]byte, error)
- func (d *MemoryDriver) GetMulti(keys []string) (map[string][]byte, error)
- func (d *MemoryDriver) Set(key string, b []byte, timeout int) error
- type Opener
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.
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
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
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
type Opener ¶
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.