cache

package
v1.30.7 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

Documentation

Overview

Package cache is an implementation of Azure caches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureCacheEntry

type AzureCacheEntry struct {
	Key  string
	Data interface{}

	// The lock to ensure not updating same entry simultaneously.
	Lock sync.Mutex
	// time when entry was fetched and created
	CreatedOn time.Time
}

AzureCacheEntry is the internal structure stores inside TTLStore.

type AzureCacheReadType

type AzureCacheReadType int

AzureCacheReadType defines the read type for cache data

const (
	// CacheReadTypeDefault returns data from cache if cache entry not expired
	// if cache entry expired, then it will refetch the data using getter
	// save the entry in cache and then return
	CacheReadTypeDefault AzureCacheReadType = iota
	// CacheReadTypeUnsafe returns data from cache even if the cache entry is
	// active/expired. If entry doesn't exist in cache, then data is fetched
	// using getter, saved in cache and returned
	CacheReadTypeUnsafe
	// CacheReadTypeForceRefresh force refreshes the cache even if the cache entry
	// is not expired
	CacheReadTypeForceRefresh
)

type GetFunc

type GetFunc func(key string) (interface{}, error)

GetFunc defines a getter function for timedCache.

type Resource added in v1.28.0

type Resource interface {
	Get(key string, crt AzureCacheReadType) (interface{}, error)
	GetWithDeepCopy(key string, crt AzureCacheReadType) (interface{}, error)
	Delete(key string) error
	Set(key string, data interface{})
	Update(key string, data interface{})

	GetStore() cache.Store
	Lock()
	Unlock()
}

Resource operations

func NewTimedCache added in v1.28.0

func NewTimedCache(ttl time.Duration, getter GetFunc, disabled bool) (Resource, error)

NewTimedCache creates a new azcache.Resource.

type ResourceProvider added in v1.28.0

type ResourceProvider struct {
	Getter GetFunc
}

func (*ResourceProvider) Delete added in v1.28.0

func (c *ResourceProvider) Delete(_ string) error

func (*ResourceProvider) Get added in v1.28.0

func (c *ResourceProvider) Get(key string, _ AzureCacheReadType) (interface{}, error)

func (*ResourceProvider) GetStore added in v1.28.0

func (c *ResourceProvider) GetStore() cache.Store

func (*ResourceProvider) GetWithDeepCopy added in v1.28.0

func (c *ResourceProvider) GetWithDeepCopy(key string, _ AzureCacheReadType) (interface{}, error)

func (*ResourceProvider) Lock added in v1.28.0

func (c *ResourceProvider) Lock()

func (*ResourceProvider) Set added in v1.28.0

func (c *ResourceProvider) Set(_ string, _ interface{})

func (*ResourceProvider) Unlock added in v1.28.0

func (c *ResourceProvider) Unlock()

func (*ResourceProvider) Update added in v1.28.0

func (c *ResourceProvider) Update(_ string, _ interface{})

type TimedCache

type TimedCache struct {
	Store     cache.Store
	MutexLock sync.RWMutex
	TTL       time.Duration
	// contains filtered or unexported fields
}

TimedCache is a cache with TTL.

func (*TimedCache) Delete

func (t *TimedCache) Delete(key string) error

Delete removes an item from the cache.

func (*TimedCache) Get

func (t *TimedCache) Get(key string, crt AzureCacheReadType) (interface{}, error)

Get returns the requested item by key.

func (*TimedCache) GetStore added in v1.28.0

func (t *TimedCache) GetStore() cache.Store

func (*TimedCache) GetWithDeepCopy added in v1.23.26

func (t *TimedCache) GetWithDeepCopy(key string, crt AzureCacheReadType) (interface{}, error)

Get returns the requested item by key with deep copy.

func (*TimedCache) Lock

func (t *TimedCache) Lock()

func (*TimedCache) Set

func (t *TimedCache) Set(key string, data interface{})

Set sets the data cache for the key. It is only used for testing.

func (*TimedCache) Unlock added in v1.28.0

func (t *TimedCache) Unlock()

func (*TimedCache) Update added in v1.26.0

func (t *TimedCache) Update(key string, data interface{})

Update updates the data cache for the key.

Jump to

Keyboard shortcuts

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