Пример #1
0
// cacheKeys will append to oldKeys, and also return as newKeys, all cache keys this finder may use to find the provided model.
// the reason there may be multiple keys is that we don't know which ancestor will be used when finding the model.
func (self finder) cacheKeys(c PersistenceContext, model interface{}, oldKeys *[]string) (newKeys []string, err error) {
	var id key.Key
	if _, id, err = getTypeAndId(model); err != nil {
		return
	}
	values := make([]interface{}, len(self.fields))
	val := reflect.ValueOf(model).Elem()
	for index, field := range self.fields {
		values[index] = val.FieldByName(field.Name).Interface()
	}
	if oldKeys == nil {
		oldKeys = &[]string{}
	}
	for id != "" {
		*oldKeys = append(*oldKeys, self.keyForValues(id.Parent(), values))
		id = id.Parent()
	}
	newKeys = *oldKeys
	return
}