cache

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheKeySubjectDescriptor string = "cache_ratify_subject_descriptor_%s"
	CacheKeyListReferrers     string = "cache_ratify_list_referrers_%s"
	CacheKeyVerifyHandler     string = "cache_ratify_verify_handler_%s"
	CacheKeyOrasAuth          string = "cache_ratify_oras_auth_%s"

	DefaultCacheType string = "ristretto"
	// DefaultCacheTTL is the default time-to-live for the cache entry.
	DefaultCacheTTL time.Duration = 10 * time.Second
	// DefaultCacheName is the default endpoint for the cache. Only used for dapr currently.
	DefaultCacheName string = "dapr-redis"
	// DefaultCacheSize is the default size of the cache in MB. Only used for ristretto currently.
	DefaultCacheSize int = 256
)

Variables

This section is empty.

Functions

func Register

func Register(name string, factory CacheFactory)

Register adds the factory to the built in providers map

Types

type CacheFactory

type CacheFactory interface {
	Create(ctx context.Context, cacheName string, cacheSize int) (CacheProvider, error)
}

CacheFactory is an interface that defines the methods that a cache provider factory must implement

type CacheProvider

type CacheProvider interface {
	// Get returns the string, json-marshalled value linked to key. Returns true/false for existence
	Get(ctx context.Context, key string) (string, bool)

	// Set adds value based on key to cache. Assume there will be no ttl. Returns true/false for success
	Set(ctx context.Context, key string, value interface{}) bool

	// SetWithTTL adds value based on key to cache. Ties ttl of entry to ttl provided. Returns true/false for success
	SetWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) bool

	// Delete removes the specified key/value from the cache
	Delete(ctx context.Context, key string) bool
}

func GetCacheProvider

func GetCacheProvider() CacheProvider

func NewCacheProvider

func NewCacheProvider(ctx context.Context, cacheType string, cacheName string, cacheSize int) (CacheProvider, error)

NewCacheProvider creates a new cache provider based on the name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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