Documentation
¶
Index ¶
- Constants
- func FinishSpan(span *sentry.Span)
- func GenerateKey(prefix string, params ...interface{}) string
- func InitializeInMemoryCache()
- func SetSpanError(span *sentry.Span, err error)
- func SetSpanSuccess(span *sentry.Span)
- func StartCacheSpan(ctx context.Context, cache, operation string, params map[string]interface{}) *sentry.Span
- type Cache
- type InMemoryCache
- func (c *InMemoryCache) Delete(_ context.Context, key string)
- func (c *InMemoryCache) DeleteByPrefix(_ context.Context, prefix string)
- func (c *InMemoryCache) Flush(_ context.Context)
- func (c *InMemoryCache) Get(_ context.Context, key string) (interface{}, bool)
- func (c *InMemoryCache) Set(_ context.Context, key string, value interface{}, expiration time.Duration)
Constants ¶
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
const DefaultCleanupInterval = 1 * time.Hour
DefaultCleanupInterval is how often expired items are removed from the cache
const DefaultExpiration = 30 * time.Minute
DefaultExpiration is the default expiration time for cache entries
const (
ExpiryDefaultInMemory = 30 * time.Minute
)
Variables ¶
This section is empty.
Functions ¶
func FinishSpan ¶ added in v1.0.17
FinishSpan safely finishes a span, handling nil spans
func GenerateKey ¶
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
SetSpanError marks a span as failed and adds error information
func SetSpanSuccess ¶ added in v1.0.17
SetSpanSuccess marks a span as successful
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