cache

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cache contains caching structures using internally by the Fleetspeak server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxAge defines how long client data should be considered valid
	// for. Variable to support unit testing.
	MaxAge = 45 * time.Second
)

Functions

This section is empty.

Types

type Clients

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

Clients is a cache of recently connected clients.

func NewClients

func NewClients() *Clients

NewClients returns a new cache of client data.

func (*Clients) Clear

func (c *Clients) Clear()

Clear empties the cache, removing all entries.

func (*Clients) Get

func (c *Clients) Get(id common.ClientID) *db.ClientData

Get returns the cached client data, if there is sufficiently fresh data in the cache, otherwise nil.

func (*Clients) GetOrRead

func (c *Clients) GetOrRead(ctx context.Context, id common.ClientID, db db.ClientStore) (data *db.ClientData, hit bool, err error)

GetOrRead returns the cached client data, if there is sufficiently fresh data in the cache. Otherwise it attempts to read the data from the provided datastore. It returns data if it finds any, hit if it was found in the cache.

func (*Clients) Size

func (c *Clients) Size() int

Size returns the current size taken up by the cache, this is a count of client records, some of which may no longer be up to date.

func (*Clients) Stop

func (c *Clients) Stop()

Stop releases the resources required for background cache maintenance. The cache should not be used once Stop has been called.

func (*Clients) Update

func (c *Clients) Update(id common.ClientID, data *db.ClientData)

Update updates or sets the cached data for a particular client. If data is nil, it clears the data for the client.

Jump to

Keyboard shortcuts

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