我有这两个域
class Country {
String name
static hasMany = [cities:City]
}
class City {
String name;
static belongsTo = [country: Country]
}
这两个表中包含的数据相对较大,并且所有屏幕都使用了这些数据,每次我选择一个国家时,都必须重新加载其所有城市。
我如何只在内存中加载一次数据,以便可以在所有屏幕中更快地访问它们。
我试着把城市急切地拿来,并尝试使用缓存插件。
谢谢
您可以将两个域类都配置为自动缓存,也可以将cities
关系缓存在Country
:
class Country {
String name
static hasMany = [cities:City]
static mapping = {
cache true
cities cache:true
}
}
class City {
String name
static belongsTo = [country: Country]
static mapping = {
cache true
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句