cache

package
v1.39.10-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cache implements caches to be used in gRPC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeoutCache

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

TimeoutCache is a cache with items to be deleted after a timeout.

func NewTimeoutCache

func NewTimeoutCache(timeout time.Duration) *TimeoutCache

NewTimeoutCache creates a TimeoutCache with the given timeout.

func (*TimeoutCache) Add

func (c *TimeoutCache) Add(key, item interface{}, callback func()) (interface{}, bool)

Add adds an item to the cache, with the specified callback to be called when the item is removed from the cache upon timeout. If the item is removed from the cache using a call to Remove before the timeout expires, the callback will not be called.

If the Add was successful, it returns (newly added item, true). If there is an existing entry for the specified key, the cache entry is not be updated with the specified item and it returns (existing item, false).

func (*TimeoutCache) Clear

func (c *TimeoutCache) Clear(runCallback bool)

Clear removes all entries, and runs the callbacks if runCallback is true.

func (*TimeoutCache) Remove

func (c *TimeoutCache) Remove(key interface{}) (item interface{}, ok bool)

Remove the item with the key from the cache.

If the specified key exists in the cache, it returns (item associated with key, true) and the callback associated with the item is guaranteed to be not called. If the given key is not found in the cache, it returns (nil, false)

Jump to

Keyboard shortcuts

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