v0.0.0-...-d88c8b5 Latest Latest

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 0



Package cache is an implementation of Azure caches.



This section is empty.


This section is empty.


This section is empty.


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
	// CacheReadTypeForceRefresh force refreshes the cache even if the cache entry
	// is not expired

type GetFunc

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

GetFunc defines a getter function for timedCache.

type TimedCache

type TimedCache struct {
	Store  cache.Store
	Lock   sync.Mutex
	Getter GetFunc
	TTL    time.Duration

TimedCache is a cache with TTL.

func NewTimedcache

func NewTimedcache(ttl time.Duration, getter GetFunc) (*TimedCache, error)

NewTimedcache creates a new TimedCache.

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) Set

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

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

Jump to

Keyboard shortcuts

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