This commit performs a significant cleanup of the codebase by removing unused functions, methods, and entire files across various internal modules. This reduces technical debt and simplifies the project structure. Key changes include: - **cache**: Removed unused cache key generators and metrics snapshots. - **dto**: Removed redundant converter functions and segment creation helpers. - **middleware**: Deleted the unused `logger.go` middleware and simplified `ratelimit.go` and `casbin.go`. - **model**: Removed unused ID helpers, database closing functions, and batch decryption logic. - **pkg**: Cleaned up unused utility functions in `circuitbreaker`, `crypto`, `cursor`, `hook`, and `utils`. - **service**: Deleted `account_cleanup_service.go` and removed unused helper functions in `log_cleanup_service.go` and `sensitive_service.go`. - **repository**: Removed unused private loading methods in `comment_repo.go`.
47 lines
856 B
Go
47 lines
856 B
Go
package cache
|
|
|
|
import "sync/atomic"
|
|
|
|
// cacheMetrics 缓存指标
|
|
type cacheMetrics struct {
|
|
hit atomic.Int64
|
|
miss atomic.Int64
|
|
decodeError atomic.Int64
|
|
setError atomic.Int64
|
|
invalidate atomic.Int64
|
|
}
|
|
|
|
// metrics 全局缓存指标实例
|
|
var metrics cacheMetrics
|
|
|
|
|
|
// recordHit 记录缓存命中
|
|
func recordHit() {
|
|
metrics.hit.Add(1)
|
|
}
|
|
|
|
// recordMiss 记录缓存未命中
|
|
func recordMiss() {
|
|
metrics.miss.Add(1)
|
|
}
|
|
|
|
// recordDecodeError 记录解码错误
|
|
func recordDecodeError() {
|
|
metrics.decodeError.Add(1)
|
|
}
|
|
|
|
// recordSetError 记录设置错误
|
|
func recordSetError() {
|
|
metrics.setError.Add(1)
|
|
}
|
|
|
|
// recordInvalidate 记录缓存失效
|
|
func recordInvalidate() {
|
|
metrics.invalidate.Add(1)
|
|
}
|
|
|
|
// recordInvalidateMultiple 记录多个缓存失效
|
|
func recordInvalidateMultiple(count int64) {
|
|
metrics.invalidate.Add(count)
|
|
}
|