Pacific73 / gorm-cache

gorm v2的即插即用、无需修改代码的旁路缓存。An easy-to-use look-aside cache solution for gorm v2 users.
Apache License 2.0
112 stars 29 forks source link

请问下,如果查询表中其中几列也会走缓存么? #9

Closed ansoda closed 1 year ago

ansoda commented 2 years ago
select id, name from user where id=1;
select * from user where id=1;

这两种情况都会走缓存么?

Pacific73 commented 1 year ago
  1. 只有第二种情况会走缓存。
  2. 只有通过gorm的相关函数进行sql查询会走缓存,这样才能触发相应的hook,直接走raw_sql是不支持缓存的
Pacific73 commented 1 year ago

There're mainly 5 kinds of operations in gorm (gorm function names in brackets):

  1. Query (First/Take/Last/Find/FindInBatches/FirstOrInit/FirstOrCreate/Count/Pluck)
  2. Create (Create/CreateInBatches/Save)
  3. Delete (Delete)
  4. Update (Update/Updates/UpdateColumn/UpdateColumns/Save)
  5. Row (Row/Rows/Scan)

We don't support caching in Row operations.