Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 2.43 KB

doc.md

File metadata and controls

65 lines (49 loc) · 2.43 KB

cache

import "github.com/vithnilica/go-cache"

Index

type Cache

type Cache[K comparable, V any] interface {
    // Get searches for a key in the cache and returns its value and a boolean indicating whether the key was found or not.
    Get(key K) (value V, found bool)
    // GetSafe is similar to Get but also checks if the value associated with the key has expired or not.
    GetSafe(key K) (V, bool)
    // GetValue returns the value associated with the key or a default value if the key is not present in the cache.
    GetValue(key K) V
    // Set inserts a key-value pair into the cache with a default duration.
    Set(key K, value V)
    // SetWithTTL inserts a key-value pair into the cache with a specified duration (TTL - Time To Live).
    SetWithTTL(key K, value V, ttl time.Duration)
    // SetAll inserts a map of key-value pairs into the cache with a default duration.
    SetAll(m map[K]V)
    // SetAllWithTTL inserts a map of key-value pairs into the cache with a specified duration.
    SetAllWithTTL(m map[K]V, ttl time.Duration)
    // Remove removes a key-value pair from the cache.
    Remove(key K)
    // IsEmpty returns true if the cache is empty.
    IsEmpty() bool
    // Size returns the number of key-value pairs in the cache.
    Size() int
    // Clear removes all key-value pairs from the cache.
    Clear()
    // CleanExpired removes all expired key-value pairs from the cache.
    CleanExpired()
    // Close stops the cleanup routine and closes the cache object.
    Close()
    // contains filtered or unexported methods
}

func New

func New[K comparable, V any](defaultTTL time.Duration, cleanupInterval time.Duration, maxSize int) Cache[K, V]

New returns a new cache object that can store key-value pairs of any comparable key type and any value type.

defaultTTL - default duration after which the values will expire (<=0 for no expiration)

cleanupInterval - cleanup interval for expired values (<=0 wihout cleanup)

maxSize - maximum size (0 wihout limit)

Generated by gomarkdoc