cache

package
v1.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixSecret                   = "secret:v1:"
	PrefixCustomer                 = "customer:v1:"
	PrefixUser                     = "user:v1:"
	PrefixTenant                   = "tenant:v1:"
	PrefixPlan                     = "plan:v1:"
	PrefixSubscription             = "subscription:v1:"
	PrefixPrice                    = "price:v1:"
	PrefixMeter                    = "meter:v1:"
	PrefixEvent                    = "event:v1:"
	PrefixWallet                   = "wallet:v1:"
	PrefixInvoice                  = "invoice:v1:"
	PrefixFeature                  = "feature:v1:"
	PrefixEntitlement              = "entitlement:v1:"
	PrefixPayment                  = "payment:v1:"
	PrefixCreditGrantApplication   = "creditgrantapplication:v1:"
	PrefixCreditNote               = "creditnote:v1:"
	PrefixTaxRate                  = "taxrate:v1:"
	PrefixTaxAssociation           = "taxassociation:v1:"
	PrefixTaxApplied               = "taxapplied:v1:"
	PrefixCoupon                   = "coupon:v1:"
	PrefixCouponAssociation        = "couponassociation:v1:"
	PrefixCouponApplication        = "couponapplication:v1:"
	PrefixAddon                    = "addon:v1:"
	PrefixAddonAssociation         = "addonassociation:v1:"
	PrefixEntityIntegrationMapping = "entity_integration_mapping:v1:"
	PrefixConnection               = "connection:v1:"
	PrefixSettings                 = "settings:v1:"
	PrefixSubscriptionLineItem     = "subscription_line_item:v1:"
)

Predefined cache key prefixes for different entity types

View Source
const DefaultCleanupInterval = 1 * time.Hour

DefaultCleanupInterval is how often expired items are removed from the cache

View Source
const DefaultExpiration = 30 * time.Minute

DefaultExpiration is the default expiration time for cache entries

View Source
const (
	ExpiryDefaultInMemory = 30 * time.Minute
)

Variables

This section is empty.

Functions

func FinishSpan added in v1.0.17

func FinishSpan(span *sentry.Span)

FinishSpan safely finishes a span, handling nil spans

func GenerateKey

func GenerateKey(prefix string, params ...interface{}) string

GenerateKey creates a cache key from a prefix and a set of parameters It joins all parameters with a colon and appends them to the prefix

func InitializeInMemoryCache

func InitializeInMemoryCache()

InitializeInMemoryCache initializes the global cache instance

func SetSpanError added in v1.0.17

func SetSpanError(span *sentry.Span, err error)

SetSpanError marks a span as failed and adds error information

func SetSpanSuccess added in v1.0.17

func SetSpanSuccess(span *sentry.Span)

SetSpanSuccess marks a span as successful

func StartCacheSpan added in v1.0.17

func StartCacheSpan(ctx context.Context, cache, operation string, params map[string]interface{}) *sentry.Span

StartCache Span creates a new span for a cache operation Returns nil if Sentry is not available in the context

Types

type Cache

type Cache interface {
	// Get retrieves a value from the cache
	// Returns the value and a boolean indicating whether the key was found
	Get(ctx context.Context, key string) (interface{}, bool)

	// Set adds a value to the cache with the specified expiration
	// If expiration is 0, the item never expires (but may be evicted)
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration)

	// Delete removes a key from the cache
	Delete(ctx context.Context, key string)

	// DeleteByPrefix removes all keys with the given prefix
	DeleteByPrefix(ctx context.Context, prefix string)

	// Flush removes all items from the cache
	Flush(ctx context.Context)
}

Cache defines the interface for caching operations

func NewInMemoryCache added in v1.0.17

func NewInMemoryCache() Cache

NewInMemoryCache creates a new InMemoryCache instance

type InMemoryCache

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

InMemoryCache implements the Cache interface using github.com/patrickmn/go-cache

func GetInMemoryCache

func GetInMemoryCache() *InMemoryCache

GetCache returns the global cache instance

func Initialize

func Initialize(log *logger.Logger) *InMemoryCache

Initialize initializes the cache system

func (*InMemoryCache) Delete

func (c *InMemoryCache) Delete(_ context.Context, key string)

Delete removes a key from the cache

func (*InMemoryCache) DeleteByPrefix

func (c *InMemoryCache) DeleteByPrefix(_ context.Context, prefix string)

DeleteByPrefix removes all keys with the given prefix

func (*InMemoryCache) Flush

func (c *InMemoryCache) Flush(_ context.Context)

Flush removes all items from the cache

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(_ context.Context, key string) (interface{}, bool)

Get retrieves a value from the cache

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(_ context.Context, key string, value interface{}, expiration time.Duration)

Set adds a value to the cache with the specified expiration

Jump to

Keyboard shortcuts

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