feat(base): 添加邮箱注册码功能及用户注册接口 - 在 `sessionManager` 中新增邮件注册码缓存管理实例和相关方法 - 实现生成、保存、验证、删除邮件注册码的逻辑 - 新增 `/reg` 和 `/email` 接口用于用户注册和发送验证码 - 引入 `golang-lru` 依赖以支持限流缓存功能 - 调整包导入顺序,优化代码结构 ```
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright IBM Corp. 2014, 2025
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Package simplelru provides simple LRU implementation based on build-in container/list.
|
|
package simplelru
|
|
|
|
// LRUCache is the interface for simple LRU cache.
|
|
type LRUCache[K comparable, V any] interface {
|
|
// Adds a value to the cache, returns true if an eviction occurred and
|
|
// updates the "recently used"-ness of the key.
|
|
Add(key K, value V) bool
|
|
|
|
// Returns key's value from the cache and
|
|
// updates the "recently used"-ness of the key. #value, isFound
|
|
Get(key K) (value V, ok bool)
|
|
|
|
// Checks if a key exists in cache without updating the recent-ness.
|
|
Contains(key K) (ok bool)
|
|
|
|
// Returns key's value without updating the "recently used"-ness of the key.
|
|
Peek(key K) (value V, ok bool)
|
|
|
|
// Removes a key from the cache.
|
|
Remove(key K) bool
|
|
|
|
// Removes the oldest entry from cache.
|
|
RemoveOldest() (K, V, bool)
|
|
|
|
// Returns the oldest entry from the cache. #key, value, isFound
|
|
GetOldest() (K, V, bool)
|
|
|
|
// Returns a slice of the keys in the cache, from oldest to newest.
|
|
Keys() []K
|
|
|
|
// Values returns a slice of the values in the cache, from oldest to newest.
|
|
Values() []V
|
|
|
|
// Returns the number of items in the cache.
|
|
Len() int
|
|
|
|
// Returns the capacity of the cache.
|
|
Cap() int
|
|
|
|
// Clears all cache entries.
|
|
Purge()
|
|
|
|
// Resizes cache, returning number evicted
|
|
Resize(int) int
|
|
}
|