This repository has been archived on 2022-04-14. You can view files and clone it, but cannot push or open issues or pull requests.
manual-en-US/chapter-11
2020-03-27 14:29:41 +08:00
..
README.md Update documents 2020-03-27 14:29:41 +08:00

Built-in LRU memory cache provider

  1. Global Cache

Xorm implements cache support. Defaultly, it's disabled. If enable it, use below code.

cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
engine.SetDefaultCacher(cacher)

If disable some tables' cache, then:

engine.MapCacher(&user, nil)
  1. Table's Cache If only some tables need cache, then:
cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
engine.MapCacher(&user, cacher)

Caution:

  1. When use Cols methods on cache enabled, the system still return all the columns.

  2. When using Exec method, you should clear cache

engine.Exec("update user set name = ? where id = ?", "xlw", 1)
engine.ClearCache(new(User))

Cache implement theory below:

cache design