keycache

package module
v0.0.0-...-2a54452 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExceedsLengthError

type ExceedsLengthError struct {
	Object    string
	Length    int
	MaxLength int
}

ExceedsLengthError satisfies the error interface

func (*ExceedsLengthError) Error

func (e *ExceedsLengthError) Error() string

type InsufficientLengthError

type InsufficientLengthError struct {
	Object    string
	Length    int
	MinLength int
}

InsufficientLengthError satisfies the error interface

func (*InsufficientLengthError) Error

func (e *InsufficientLengthError) Error() string

type Item

type Item interface {
	Key() string
	Item() []byte
}

Item is an interface for the object stored in memory

type KeyCache

type KeyCache struct {
	OStore         []ObjectStore
	Expire         time.Duration // object expire duration
	LimitObjectLen bool          // should number of objects be limited
	MaxObjectLen   int           // len of o.Object
	DateCreated    time.Time
	// contains filtered or unexported fields
}

KeyCache is a Fast Dataset Cache

func (*KeyCache) Add

func (k *KeyCache) Add(objectStoreKey string, item Item) (bool, error)

Add an object to the cache

func (*KeyCache) Delete

func (k *KeyCache) Delete(objectStoreKey string, objectKey string) error

Delete an object from cache

func (*KeyCache) Generate

func (k *KeyCache) Generate(key string) error

Generate generates an object store an initializes it

func (*KeyCache) Get

func (k *KeyCache) Get(objectStoreKey string, objectKey string) (Object, error)

Get an object from the cache

func (*KeyCache) Len

func (k *KeyCache) Len() int

Len returns len of o.Object

func (*KeyCache) Purge

func (k *KeyCache) Purge() int

Purge cleans the cache

func (*KeyCache) PurgeOldest

func (k *KeyCache) PurgeOldest() error

PurgeOldest purges oldest objects

func (*KeyCache) PurgeTimer

func (k *KeyCache) PurgeTimer(interval time.Duration, debug bool)

PurgeTimer purges the KeyCache every x time.Duration's

func (*KeyCache) Read

func (k *KeyCache) Read(key string) (ObjectStore, error)

Read searches the object store for keys and returns a struct

func (*KeyCache) SetExpire

func (k *KeyCache) SetExpire(key string, expire time.Duration, enableLocalExpire bool) error

SetExpire sets an expiration date on a ObjectStore

type NoCacheEntryError

type NoCacheEntryError struct {
	Object        string
	ShouldContain string
}

NoCacheEntryError satisfies the error interface

func (*NoCacheEntryError) Error

func (e *NoCacheEntryError) Error() string

type NoObjectError

type NoObjectError struct {
	Struct              string
	ShouldContainObject string
}

NoObjectError satisfies the error interface

func (*NoObjectError) Error

func (e *NoObjectError) Error() string

type Object

type Object struct {
	Item        Item      // Item interface
	Valid       bool      // was the Object initialized (true) or is it default value (false)
	DateCreated time.Time // when was the Object created
}

Object is an Item helper type

func (*Object) IsExpired

func (o *Object) IsExpired(expireDuration time.Duration) bool

IsExpired checks if the Object has expired

type ObjectStore

type ObjectStore struct {
	Key    string
	Object []Object

	LocalExpire  bool          // use local expire duration (ObjectStore.Expire)
	Expire       time.Duration // local expire duration
	DateCreated  time.Time
	DateModified time.Time
	// contains filtered or unexported fields
}

ObjectStore contains objects and their metadata

func (*ObjectStore) Add

func (o *ObjectStore) Add(item Item) bool

Add a new Object to ObjectStore (returns true if an existing object has been replaced)

func (*ObjectStore) Delete

func (o *ObjectStore) Delete(key string) error

Delete objects from the ObjectStore

func (*ObjectStore) Get

func (o *ObjectStore) Get(key string) (Object, error)

Get objects from the ObjectStore

func (*ObjectStore) Len

func (o *ObjectStore) Len() int

Len returns the length of o.Object

func (*ObjectStore) Purge

func (o *ObjectStore) Purge(expireDuration time.Duration) int

Purge deletes all expired Object's in ObjectStore, ignores expireDuration if o.LocalExpire is true

func (*ObjectStore) PurgeOldest

func (o *ObjectStore) PurgeOldest() error

PurgeOldest deletes old elements to make space for new ones

func (*ObjectStore) SetExpire

func (o *ObjectStore) SetExpire(expire time.Duration, enableLocalExpire bool)

SetExpire sets the local object expiration time.Duration

Jump to

Keyboard shortcuts

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