this project is used to generate gorm model and repository from mysql database and other databases.
go install github.com/xiaoshouchen/gorm-generator@latestgorm-generator{
"databases": [
{
"scheme": "panda-trip",
"package_name": "model",
"connect": {
"type": "mysql",
"host": "localhost",
"port": "3306",
"user": "root",
"password": "password"
},
"table_filter_option": "all",
"tables": [],
"cache_expiration": [
{
"name": "users",
"time": 3600
}
]
}
]
}- you should add cache expiration time for table in config
- the cache key is
table_name_%s - the cache value is the table data
- the cache expiration time is the time you set in config
- batch get cache data by ids , if cache not exists, will get data from database and set cache
- if some ids not exists in database, it also set cache for these ids, but the value is
{},avoid cache penetration, {} empty cache expiration time is 1 day always
- watch canal event
- when insert/update/delete event, will sync cache
- table_name_cache.go is generated by gorm-generator , do not modify it ,and if you want to add or edit cache, you should modify table_name_repo.go for additional operations