Skip to main content

Module prepared_cache

Module prepared_cache 

Source
Expand description

v6.5.0 PreparedStatement 句柄缓存

缓存数据库侧 PreparedStatement 句柄,按连接分桶(句柄绑定连接), 跨连接共享 LRU 淘汰顺序。与既有 PlanCache(应用侧 AST 缓存)职责分离。

特性:

  • 按连接 ID 分桶(SQLx prepared statement 绑定连接)
  • bucket 级别 LRU 淘汰(max_size_per_conn 上限)
  • 表级精确失效(table_index 索引)
  • 连接级失效(invalidate_conn,连接关闭时调用)
  • 原子统计(命中/未命中/淘汰/降级/失效)
  • 句柄以闭包形式存储(避免在 sz-orm-core 暴露 SQLx 类型)

Structs§

PreparedStatementCache
PreparedStatement 句柄缓存
PreparedStatementCacheStats
PreparedStatement 缓存统计(原子计数器)
PreparedStatementCacheStatsSnapshot
统计快照(用于读取一致性视图)

Enums§

PreparedLookup
缓存查找结果

Functions§

extract_tables_simple
从 SQL 中提取表名(简单字符串扫描,不依赖 sqlparser)

Type Aliases§

ConnId
连接唯一标识(连接生命周期内不变)
ExecuteFn
句柄执行闭包类型(Arc 包装,支持从 RwLock 中 clone 出来后释放锁再 await)