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

What's the difference between Search cache and Primary cache? #20

Closed rts-gordon closed 1 year ago

rts-gordon commented 1 year ago

Hi @Pacific73 I noticed that there are four Cache level:

const (
    CacheLevelOff         CacheLevel = 0
    CacheLevelOnlyPrimary CacheLevel = 1
    CacheLevelOnlySearch  CacheLevel = 2
    CacheLevelAll         CacheLevel = 3
)

What's the difference between Search cache and Primary cache, or All cache? Thanks a lot.

Pacific73 commented 1 year ago

Primary cache gets objects cached when you use db.Where("id IN (?)", []int{1,2,3}). It's based on primary key, a.k.a, id.

Search cache gets objects cached using complete SQL as key.