limitedcache

package module
v0.0.0-...-c81f76c Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: Apache-2.0, MIT Imports: 12 Imported by: 0

README

limitedcache

httpcache compatible cache with limited size on disk. Size is limited to number of items. Additionly this cache sends operation types, keys, errors to a channel. This can be used to make changes in cache externally - eg. remove some content earlier from cache.

Code is heavily copied from github.com/gregjones/httpcache

Documentation

Index

Constants

View Source
const (
	// GetOp cache item operation.
	GetOp = OpType(iota)
	// SetOp cache item operation.
	SetOp
	// DeleteOp cache item operation.
	DeleteOp
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is an implementation of httpcache.Cache with persistent storage.

func New

func New(basePath string, limit int) *Cache

New returns a new Cache that will store files in basePath

func NewWithDiskv

func NewWithDiskv(d *diskv.Diskv, limit int) *Cache

NewWithDiskv returns a new Cache using the provided Diskv as underlying storage.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes the response with key from the cache.

func (*Cache) Events

func (c *Cache) Events() <-chan CacheOp

Events returns channel with cache operations messages.

func (*Cache) Get

func (c *Cache) Get(key string) (resp []byte, ok bool)

Get returns the response corresponding to key if present.

func (*Cache) LoadKeysFromDisk

func (c *Cache) LoadKeysFromDisk(basePath string)

LoadKeysFromDisk - loads cache keys to memory to keep limited cache

func (*Cache) Lost

func (c *Cache) Lost() int

Lost returns number of lost messages - not sent to channel.

func (*Cache) ResetLost

func (c *Cache) ResetLost() int

ResetLost sets lost counter to 0.

func (*Cache) Set

func (c *Cache) Set(key string, resp []byte)

Set saves a response to the cache as key.

type CacheOp

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

CacheOp - operations on cache with key and cache file name.

func (*CacheOp) File

func (em *CacheOp) File() string

File returns cache operation filename on disk.

func (*CacheOp) Key

func (em *CacheOp) Key() string

Key returns cache operation key.

func (*CacheOp) Operation

func (em *CacheOp) Operation() string

Operation returns name of cache operation.

func (*CacheOp) OperationID

func (em *CacheOp) OperationID() OpType

OperationID returns type of cache operation.

func (*CacheOp) Status

func (em *CacheOp) Status() error

Status returns cache operation error.

type OpType

type OpType uint8

OpType is cache operation type enum.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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