Documentation
¶
Index ¶
- func DecodeFromHex[T any](encodedStr string) (value T, err error)
- func EncodeToHex(value any) (string, error)
- type Cache
- type FileCache
- func (c *FileCache[K, V]) Clear()
- func (c *FileCache[K, V]) Delete(key K)
- func (c *FileCache[K, V]) Get(key K) (value V, ok bool)
- func (c *FileCache[K, V]) GetDefault(key K, _default V) V
- func (c *FileCache[K, V]) GetOrSet(key K, newVal V, ttl time.Duration) (V, bool, error)
- func (c *FileCache[K, V]) HasKey(key K) bool
- func (c *FileCache[K, V]) Keys() []K
- func (c *FileCache[K, V]) Set(key K, value V, ttl time.Duration) error
- func (c *FileCache[K, V]) Stop()
- type FileCacheShard
- type FileNode
- type MemCache
- func (c *MemCache[K, V]) Clear()
- func (c *MemCache[K, V]) Delete(key K)
- func (c *MemCache[K, V]) Get(key K) (value V, ok bool)
- func (c *MemCache[K, V]) GetDefault(key K, _default V) V
- func (c *MemCache[K, V]) GetOrSet(key K, newVal V, ttl time.Duration) (V, bool, error)
- func (c *MemCache[K, V]) HasKey(key K) bool
- func (c *MemCache[K, V]) Keys() []K
- func (c *MemCache[K, V]) Set(key K, value V, ttl time.Duration) error
- func (c *MemCache[K, V]) Stop()
- type MemCacheNode
- type MemCacheShard
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeFromHex ¶
DecodeFromHex 使用 Gob 反序列化为原始类型
func EncodeToHex ¶
Types ¶
type Cache ¶
type Cache[K comparable, V any] interface { // Set a value in the cache if the key does not already exist. If // timeout is given, use that timeout for the key; Set(key K, value V, ttl time.Duration) error // Get a given key from the cache. Get(key K) (value V, ok bool) // GetDefault a given key from the cache. If the key does not exist, return // default, which itself defaults to nil. GetDefault(key K, _default V) V // GetOrSet fetch a given key from the cache. If the key does not exist, // add the key and set it to the new value. If ttl is given, use that // timeout for the key. // The value result is the value for the existing key or the given new value. // The loaded result is true if the value was loaded, false if stored. // The err result reports error if setting a new val fails. GetOrSet(key K, newVal V, ttl time.Duration) (V, bool, error) // HasKey returns True if the key is in the cache and has not expired. HasKey(key K) bool // Keys returns a slice of all keys in the cache in order of usage. // note: Not all keys are exist because they may have expired and not yet been cleaned up. Keys() []K // Delete a key from the cache and return whether it succeeded, failing // silently. Delete(key K) // Clear *all* values from the cache at once. Clear() }
type FileCache ¶
type FileCache[K comparable, V any] struct { // contains filtered or unexported fields }
FileCache represents the file-based shard cache system
func NewFileCache ¶
func NewFileCache[K comparable, V any](numShards int, baseDir string, cleanupInterval time.Duration) (*FileCache[K, V], error)
NewFileCache initializes a new sharded file-based cache.
func (*FileCache[K, V]) GetDefault ¶
func (c *FileCache[K, V]) GetDefault(key K, _default V) V
type FileCacheShard ¶
type FileCacheShard[K comparable, V any] struct { // contains filtered or unexported fields }
FileCacheShard represents a single shard of the cache
type MemCache ¶
type MemCache[K comparable, V any] struct { // contains filtered or unexported fields }
MemCache is a simple lru cache.
func NewMemCache ¶
func (*MemCache[K, V]) Delete ¶
func (c *MemCache[K, V]) Delete(key K)
Delete removes a specific key from the cache.
func (*MemCache[K, V]) GetDefault ¶
func (c *MemCache[K, V]) GetDefault(key K, _default V) V
type MemCacheNode ¶
type MemCacheNode[K comparable, V any] struct { Key K Value V Expiration int64 // contains filtered or unexported fields }
MemCacheNode is a doubly linked list
func (*MemCacheNode[K, V]) IsExpired ¶
func (node *MemCacheNode[K, V]) IsExpired() bool
IsExpired check whether it has expired.
type MemCacheShard ¶
type MemCacheShard[K comparable, V any] struct { // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.