Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no methods to clear or disable the fileCache and infoCache #99

Closed
samshan08 opened this issue Nov 27, 2018 · 1 comment
Closed

no methods to clear or disable the fileCache and infoCache #99

samshan08 opened this issue Nov 27, 2018 · 1 comment

Comments

@samshan08
Copy link

when using gnostic to parse the openAPIv3 document, our code is as follow:

func unmarshalApiSpec(svcName string, apiSpecStr string) (*openapi_v3.Document, error) {
	decodeValue, err := Base64Decode(apiSpecStr)
	if nil != err {
		return nil, err
	}
	rawText, err := DeCompressDefinition(decodeValue)
	if nil != err {
		return nil, err
	}
	info, err := compiler.ReadInfoFromBytes(svcName, rawText)
	if err != nil {
		return nil, err
	}
	doc, err := openapi_v3.NewDocument(info, compiler.NewContext("$root", nil))
	if err != nil {
		return nil, err
	}
	return doc, nil
}

We encounter the problem that: when we call unmarshalApiSpec twice using the same svcName, but different apiSpecStr, it is always return the first parse result unless you restart the process.
As we study the code, we found that gnostic has cache for cache the unmarshal result, as follow:

func ReadInfoFromBytes(filename string, bytes []byte) (interface{}, error) {
	initializeInfoCache()
	cachedInfo, ok := **infoCache[filename]
	if ok {
		if verboseReader {
			log.Printf("Cache hit info for file %s", filename)
		}
		return cachedInfo, nil
	}
	if verboseReader {
		log.Printf("Reading info for file %s", filename)
	}
	var info yaml.MapSlice
	err := yaml.Unmarshal(bytes, &info)
	if err != nil {
		return nil, err
	}
	if len(filename) > 0 {
		infoCache[filename] = info
	}
	return info, nil
}

We did not find any methods to clear or disable this cache.

@timburks
Copy link
Contributor

Fixed with #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants