Skip to content

Commit d185614

Browse files
committed
Add example in README.md
1 parent ea2a511 commit d185614

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,20 @@ SELECT * from fruits_20241204 where id=? [1]
9494
```
9595
可以看见${date}被替换成"20241204",而#{id}替换成了'?',同时param_list中只有一个参数值为1。
9696

97-
基于安全性的考虑,为了防止SQL注入,建议只要能使用#{}就不要使用${},除非你有足够的把握。
97+
基于安全性的考虑,为了防止SQL注入,建议只要能使用#{}就不要使用${},除非你有足够的把握。
98+
99+
## Cache
100+
mybatis-py为每条连接维护一个缓存池,淘汰策略是LRU,你可以定义池最大的字节容量,如果你不想使用cache,可以设置参数配置,代码如下:
101+
```python
102+
def main():
103+
# 连接到 MySQL 数据库
104+
# conn = mysql.connector.connect(
105+
# host="localhost", # MySQL 主机地址
106+
# user="mybatis", # MySQL 用户名
107+
# password="mybatis", # MySQL 密码
108+
# database="mybatis" # 需要连接的数据库
109+
# )
110+
111+
mb = Mybatis(conn, "mapper", cache_memory_limit=50*1024*1024) # 容量上限为50MB
112+
mb2 = Mybatis(conn, "mapper", cache_memory_limit=None) # 不开启缓存
113+
```

0 commit comments

Comments
 (0)