server

package
v0.0.0-...-b18812d Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoKey for key not found
	ErrNoKey = errors.New("No key found")
	// ErrKeyExpired for keys expired
	ErrKeyExpired = errors.New("Key expired")
)

Functions

This section is empty.

Types

type Cache

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

Cache is a struct in which the cache's methods synchronize access to this map, so it is not recommended to keep any references to the map around after creating a cache.

func NewCacheService

func NewCacheService(defaultExpiration, cleanupInterval time.Duration) *Cache

NewCacheService is used to initialize a new cache. Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one, the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.deleteExpired().

func (Cache) Add

func (c Cache) Add(ctx context.Context, item *api.Item) (*api.Item, error)

Add is used to add key/value pair to the cache.

func (Cache) DeleteAll

func (c Cache) DeleteAll(ctx context.Context, in *empty.Empty) (*api.Success, error)

Delete all items from the cache.

func (Cache) DeleteKey

func (c Cache) DeleteKey(ctx context.Context, args *api.GetKey) (*api.Success, error)

DeleteKey deletes an item from the cache. Does nothing if the key is not in the cache.

func (Cache) Get

func (c Cache) Get(ctx context.Context, args *api.GetKey) (*api.Item, error)

Get method is used to key/value pair while providing key as args

func (Cache) GetAllItems

func (c Cache) GetAllItems(ctx context.Context, in *empty.Empty) (*api.AllItems, error)

GetAllItems method get all unexpired keys from the cache

func (Cache) GetByPrefix

func (c Cache) GetByPrefix(ctx context.Context, args *api.GetKey) (*api.AllItems, error)

GetByPrefix method is all keys that match the prefix while providing key as args

type Item

type Item struct {
	Object     interface{}
	Expiration int64
}

Item items value of key and expiration

Jump to

Keyboard shortcuts

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