cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	// Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
	Get(key string) (*Item, bool)

	// Set an item to the cache, replacing any existing item.
	Set(key string, ttl time.Duration, item *Item)

	// Count returns the number of items in the cache.
	Count() uint32
}

Cacher interface describes something, who can read and write data into fast storage (faster than local filesystem).

type InMemoryCache

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

InMemoryCache implements Cacher interface and uses memory as a storage.

func NewInMemoryCache

func NewInMemoryCache(cleanupInterval time.Duration) *InMemoryCache

NewInMemoryCache creates cacher implementation, that uses memory as a storage.

func (*InMemoryCache) Count

func (c *InMemoryCache) Count() uint32

Count returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(key string) (*Item, bool)

Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(key string, ttl time.Duration, item *Item)

Set an item to the cache, replacing any existing item. If the duration is -1, the item never expires.

type Item

type Item struct {
	ModifiedTime time.Time
	Content      io.ReadSeeker
}

Item is structured cache item.

Jump to

Keyboard shortcuts

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