database/gdb: CacheOption.Force 从不缓存空结果,每次未命中仍会访问数据库
作者: lingcoder创建于 2026年9月23日更新于 2026年9月23日
database/gdb/gdb_model_cache.go saveSelectResultToCache:
if result != nil && result.IsEmpty() {
if m.cacheOption.Force {
result = Result{}
} else {
result = nil
}
}When All() returns nil when no rows are found, result != nil is false, and the entire branch is skipped, and nil is stored in the cache. When reading from the cache, getSelectResultFromCache returns nil, and the caller if result != nil { return } treats it as a cache miss, so it is hit.
内容来源: gogf/gf