func cachedInAgentPolicy()

in lib/store/cleanup.go [135:160]


func cachedInAgentPolicy(left, right fInfo) int {
	// For context, the order when downloading a file is:
	// 1. Upon downloading the last byte of a file, its download time is set.
	// 2. The application logic sets the access time.
	// 3. no-op - The file is moved from the upload dir to the upload cache, but this changes neither the access nor download times.
	// 4. [optional] File is downloaded by a consumer (proxy or agent) and the access time is updated.

	if isDownloadedByConsumer(left) && !isDownloadedByConsumer(right) {
		return -1
	}
	if !isDownloadedByConsumer(left) && isDownloadedByConsumer(right) {
		return 1
	}
	// At this point, both files must be downloaded by a consumer (proxy/agent).

	// The ifs below check if one file is for sure cached by an agent, while the other isn't.
	if forSureInAgent(left) && !forSureInAgent(right) {
		return -1
	}
	if !forSureInAgent(left) && forSureInAgent(right) {
		return 1
	}

	// If none of the heuristics above work out, we default to a basic LRU cache, keeping the most recently accessed files.
	return int(left.accessTime.Sub(right.accessTime))
}