cache

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 4 Imported by: 5

Documentation

Overview

Package cache provides a time cache implementation safe for concurrent use without the need of additional locking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeCache

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

TimeCache provides a time cache safe for concurrent use by multiple goroutines without additional locking or coordination.

func NewTimeCache

func NewTimeCache(timespan time.Duration) *TimeCache

NewTimeCache creates a new cache instance with provided timespan.

func (*TimeCache) Add

func (tc *TimeCache) Add(item string) bool

Add adds an entry to the cache. Returns `true` if entry was not present in the cache and was successfully added into it. Returns `false` if entry is already in the cache. This method is synchronized.

func (*TimeCache) Has

func (tc *TimeCache) Has(item string) bool

Has checks presence of an entry in the cache. Returns `true` if entry is present and `false` otherwise.

func (*TimeCache) Sweep

func (tc *TimeCache) Sweep()

Sweep removes old entries. That is those for which caching timespan has passed.

Jump to

Keyboard shortcuts

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