Documentation
¶
Index ¶
- Variables
- func Clear()
- func Close()
- func Exist(key string) bool
- func Get[T any](key string) (T, bool)
- func New(conf ...Config) error
- func Put[T any](key string, value T, ttl time.Duration)
- func Remove(key string) bool
- func Set[T any](key string, value T, ttl time.Duration) error
- type Cago
- type Config
- type Entry
- type Timezone
Constants ¶
This section is empty.
Variables ¶
var ErrKeyExists = errors.New("key already exists")
ErrKeyExists is returned by Set when a key already exists and has not expired.
Functions ¶
func Get ¶
Get retrieves a typed value by key. It returns the zero value of T and false if the key does not exist or has expired. The type parameter T must match the stored value's concrete type.
func New ¶
New initializes the global cache instance and starts the janitor. Calling New multiple times is safe; only the first call creates the cache.
Types ¶
type Cago ¶
type Cago struct {
// contains filtered or unexported fields
}
Cago is a lightweight, in‑memory, thread‑safe key/value cache with TTL support. It runs a background janitor that periodically removes expired entries. All exported methods are safe for concurrent use.
type Config ¶
type Config struct {
// CleanInterval defines how often the janitor scans for expired keys.
// Default: 1 second if zero.
CleanInterval time.Duration
// Timezone is reserved for future use and kept for compatibility.
// It does not affect cache behavior.
Timezone Timezone
}
Config controls cache behavior.
type Entry ¶
type Entry struct {
Key string
Value any
ExpiresAt int64 // unix milli; 0 means never expires
CreatedAt int64 // unix milli
UpdatedAt int64 // unix milli
}
Entry represents a single cache item. Value holds the stored data, ExpiresAt is a unix timestamp in milliseconds. A zero ExpiresAt means the entry never expires.
type Timezone ¶
type Timezone string
Timezone is a placeholder type for potential future features that may depend on time zones. It is currently unused by the cache engine.
const ( // Universal TimezoneUTC Timezone = "UTC" // UTC+00 TimezoneLocal Timezone = "Local" // host system local timezone // Indonesia TimezoneWIB Timezone = "Asia/Jakarta" // UTC+07 TimezoneWITA Timezone = "Asia/Makassar" // UTC+08 TimezoneWIT Timezone = "Asia/Jayapura" // UTC+09 // Asia TimezoneTokyo Timezone = "Asia/Tokyo" // UTC+09 TimezoneSingapore Timezone = "Asia/Singapore" // UTC+08 TimezoneBangkok Timezone = "Asia/Bangkok" // UTC+07 TimezoneShanghai Timezone = "Asia/Shanghai" // UTC+08 TimezoneDubai Timezone = "Asia/Dubai" // UTC+04 // Europe TimezoneLondon Timezone = "Europe/London" // UTC+00 (DST +01) TimezoneBerlin Timezone = "Europe/Berlin" // UTC+01 (DST +02) TimezoneParis Timezone = "Europe/Paris" // UTC+01 (DST +02) TimezoneMoscow Timezone = "Europe/Moscow" // UTC+03 // America TimezoneNewYork Timezone = "America/New_York" // UTC-05 (DST -04) TimezoneLosAngeles Timezone = "America/Los_Angeles" // UTC-08 (DST -07) TimezoneChicago Timezone = "America/Chicago" // UTC-06 (DST -05) TimezoneSaoPaulo Timezone = "America/Sao_Paulo" // UTC-03 TimezoneMexicoCity Timezone = "America/Mexico_City" // UTC-06 (DST -05) // Australia / Pacific TimezoneSydney Timezone = "Australia/Sydney" // UTC+10 (DST +11) TimezoneAuckland Timezone = "Pacific/Auckland" // UTC+12 (DST +13) TimezoneHonolulu Timezone = "Pacific/Honolulu" // UTC-10 )