cacheManager

package
v0.0.0-...-33e56a9 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheManager

type CacheManager struct {
	APIKey string
	// contains filtered or unexported fields
}

CacheManager is the struct defined to group and contain all the methods that interact with the caching mechanism.

func New

func New(metrics *prometheus.GaugeVec, t time.Duration, k string) *CacheManager

New is the function to create the struct CacheManager. Parameters: - t: a time.Duration with the max duration alive of the cache elements. - k: string containing the APIKey/token in case of need. Returns: - CacheManager: struct to interact with CacheManager subsystem functionalities.

func (*CacheManager) Add

func (c *CacheManager) Add(plainName string, fetcher cacheFetchFunction)

Add function job is to insert a new model in the cache. What it does is link the model with a fetching function and, if wanted, with a plain text name, so later in order to retrieve things from the cache they can be refereced either by the struct model or the plain text name. Paramenters: - plainName: a case insensitive name/alias to retrieve the data. - fetcher: the cacheFetchFunction used to retrieve the data.

func (*CacheManager) Get

func (c *CacheManager) Get(id interface{}, model string, token string) (interface{}, error)

Get function job is to retrieve an object from the cache or fetch it from the source and upgrade the copy in the cache in case the expiration time has been exceeded. Paramenters: - id: the reference id of the object. - model: the text alias set to reference the model. - token: Keycloak Bearer token, completely optional. Returns: - The object associated with the request - An error raised in case something went wrong while retrieving the object.

Jump to

Keyboard shortcuts

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