memory

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache holds cache entries and a lock to allow manage concurrent access.

type CacheEntries

type CacheEntries map[string]*Item

CacheEntries is a map that holds cache items.

type CachePool

type CachePool map[reflect.Type]*Cache

CachePool holds type specific Cache instances. This structure allows to optimize locking of the cache. As every type has its own Cache instance, the entire CachePool does not need to be locked longer than necessary, as large part of data is in the dedicated Cache instances.

type InMemoryCacheProvider

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

InMemoryCacheProvider provides the ability to cache data in the RAM.

func New

func New(lifetime time.Duration) *InMemoryCacheProvider

New creates a new cache with the specified lifetime (in seconds).

func (*InMemoryCacheProvider) Get

func (provider *InMemoryCacheProvider) Get(key string, t reflect.Type) (interface{}, bool)

Get an Item from the cache, if there is a valid one. The function will return nil if there is no valid cache entry. A valid cache entry is present when:

  1. for the given type and key an item can be found.
  2. the found items lifetime is not exceeded

func (*InMemoryCacheProvider) Invalidate

func (provider *InMemoryCacheProvider) Invalidate(key string, t reflect.Type) bool

Invalidate manually invalidates the cache item behind the supplied key, if there is a cache item.

func (*InMemoryCacheProvider) Shutdown added in v0.4.0

func (provider *InMemoryCacheProvider) Shutdown()

Shutdown on in-memory cache does nothing, as no external services are used.

func (*InMemoryCacheProvider) Update

func (provider *InMemoryCacheProvider) Update(key string, t reflect.Type, value interface{}) error

Update adds and item to the cache or updates it.

func (*InMemoryCacheProvider) UseGarbageCollector

func (provider *InMemoryCacheProvider) UseGarbageCollector() bool

UseGarbageCollector configures a periodic job that throws out items from the cache that are invalid, to prevent unnecessary memory usage.

Note that currently there is no method to stop the garbage collector once started. However, this is fine for the applications needs.

type Item

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

Item is a single cache item that holds the value of the item and the time the value has been pulled.

Jump to

Keyboard shortcuts

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