cache

package
v0.0.0-...-4d052a6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set used to save in the cache the status code and the content of the URL
	Set(URL string, statusCode int, content []byte) error
	// Get used to get back data from the cache
	Get(URL string) (int, []byte, error)
	// Clear removes all records from the cache
	Clear() error
}

Cache interface used to store locally and temporarily pages downloaded from Linguee. Made to reduce the load on Linguee servers and to speed up the API.

func NewMemoryCache

func NewMemoryCache() Cache

NewMemoryCache returns a memory cache object

type DBCache

type DBCache struct {
	Database *sql.DB
	Table    string
	Timeout  time.Duration
}

DBCache is an object which implements the cache interface, and stores data in a database in compressed format

func (DBCache) Clear

func (c DBCache) Clear() error

Clear removes all records from the cache

func (DBCache) Get

func (c DBCache) Get(URL string) (statusCode int, content []byte, err error)

Get is used to get back data from the cache

func (DBCache) Set

func (c DBCache) Set(URL string, statusCode int, content []byte) error

Set used to save in the cache the status code and the content of the URL

type MemoryCache

type MemoryCache map[string]memoryCacheItem

MemoryCache is an object which implements the cache interface and stores data in memory (dummy implementation: use in production with care, since never releases the cache, prone to memory leaks)

func (MemoryCache) Clear

func (c MemoryCache) Clear() error

Clear removes all records from the cache

func (MemoryCache) Get

func (c MemoryCache) Get(URL string) (statusCode int, content []byte, err error)

Get used to get back data from the cache

func (MemoryCache) Set

func (c MemoryCache) Set(URL string, statusCode int, content []byte) error

Set used to save in the cache the status code and the content of the URL

Jump to

Keyboard shortcuts

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