ttl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package ttl provides functionality for managing time-to-live (TTL) values in the cache. It includes utilities for validating TTL durations, calculating expiration times, and checking if values have expired.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpirationTime

func GetExpirationTime(ttl time.Duration, config Config) time.Time

GetExpirationTime calculates the expiration time for a TTL value

func IsExpired

func IsExpired(expirationTime time.Time) bool

IsExpired checks if a given time has expired

func Normalize

func Normalize(ttl time.Duration, config Config) time.Duration

Normalize normalizes a TTL value according to the configuration

func Validate

func Validate(ttl time.Duration, config Config) error

Validate validates a TTL value against the configuration

Types

type Config

type Config struct {
	// DefaultTTL is the default time-to-live for cache entries
	DefaultTTL time.Duration

	// MinTTL is the minimum allowed TTL value
	MinTTL time.Duration

	// MaxTTL is the maximum allowed TTL value
	MaxTTL time.Duration

	// ZeroTTLMeansNoExpiry determines if TTL of 0 means no expiry
	ZeroTTLMeansNoExpiry bool
}

Config represents configuration for TTL behavior

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default TTL configuration

func TestConfig

func TestConfig() Config

TestConfig returns a TTL configuration suitable for testing It allows shorter TTLs than the default configuration

Jump to

Keyboard shortcuts

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