cache

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Copyright 2016 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 The Serviced Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func At

func At(t time.Time, f func())

At sets a fake time, executes the provided function, then restores the default time getter, making it possible to test time-sensitive stuff

Types

type LRUCache

type LRUCache interface {
	// Gets the value for key; returns the value and true if found, nil and false otherwise.
	Get(key string) (interface{}, bool)

	// Add a value to the cache for the specified key.
	// If the key already exists in the cache, it's value will be replaced.
	Set(key string, value interface{})

	// Invalidate removes the record with the specified key
	Invalidate(key string)

	// Returns the current number of items in the cache.
	GetCurrentSize() int

	// Returns the maximum size of the cache.
	GetMaxSize() int
}

LRUCache defines a generic interface to an LRU cache.

type SimpleLRUCache

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

func NewSimpleLRUCache

func NewSimpleLRUCache(maxItems int, expiration time.Duration, cleanupInterval time.Duration, shutdown chan struct{}) (*SimpleLRUCache, error)

Creates a new instance of SimpleLRUCache that supports both a maximum cache size and a maximum time-to-live for each item in the cache. If on Set(), the number of active items exceeds maxItems, the oldest item will be removed to make room for the the new item. Additionally, the cache tracks the age of item and automatically removes items that have aged past their expiration time.

Parameters: maxItems - the maximum number of items in the cache expiration - the expiration time for each item added to the cache. Items older than this value will automatically

be removed.

cleanupInterval - the interval at which the cleaner runs to remove expired items from the cache.

If 0, then the cleaner is not started.  The minimum non-zero value is one second.

shutdown - a channel that can be used to shutdown the cleanup timer

func (*SimpleLRUCache) Get

func (c *SimpleLRUCache) Get(key string) (interface{}, bool)

Gets the value for key; returns the value and true if found, nil and false otherwise.

func (*SimpleLRUCache) GetCleanupInterval

func (c *SimpleLRUCache) GetCleanupInterval() time.Duration

func (*SimpleLRUCache) GetCurrentSize

func (c *SimpleLRUCache) GetCurrentSize() int

Returns the current number of items in the cache.

func (*SimpleLRUCache) GetExpiration

func (c *SimpleLRUCache) GetExpiration() time.Duration

func (*SimpleLRUCache) GetMaxSize

func (c *SimpleLRUCache) GetMaxSize() int

Returns the maximum size of the cache.

func (*SimpleLRUCache) Invalidate

func (c *SimpleLRUCache) Invalidate(key string)

Invalidate removes the service from the cache.

func (*SimpleLRUCache) Set

func (c *SimpleLRUCache) Set(key string, value interface{})

Add a value to the cache for the specified key. If the key already exists in the cache, it's value will be replaced.

Jump to

Keyboard shortcuts

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