Built-in LRU memory cache provider
Built-in LRU memory cache provider
- Global Cache
Xorm implements cache support. Defaultly, it’s disabled. If enable it, use below code.
1. cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
2. engine.SetDefaultCacher(cacher)
If disable some tables’ cache, then:
1. engine.MapCacher(&user, nil)
- Table’s Cache If only some tables need cache, then:
1. cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
2. engine.MapCacher(&user, cacher)
Caution:
- When use Cols methods on cache enabled, the system still return all the columns.
- When using Exec method, you should clear cache:
1. engine.Exec("update user set name = ? where id = ?", "xlw", 1)
2. engine.ClearCache(new(User))
Cache implement theory below:


