mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00

CacheEvictor.onStartFile currently receives a length, which is the maximum size of the content that might be written. The LRU cache evictor will make sure there's sufficient space for the specified size. If the actual size of the content is unknown, CacheDataSink passes maxCacheFileSize. The current behavior isn't ideal. It seems valid for a developer to specify maxCacheFileSize=Long.MAX_VALUE if they don't want any file fragmentation in the cache. However if they then attempt to cache something with unknown length, LRU cache will try and make room for content of length Long.MAX_VALUE, and end up evicting the entire cache to do so. This change alters the logic so a length is only passed if the actual size of the content is known. In other cases C.LENGTH_UNSET is now passed. The LRU evictor will not evict until after the file is committed. Note a custom LRU evictor could still opt to evict to ensure some application specified amount of space, if that's the desired behavior. PiperOrigin-RevId: 227509525