How to close a Snapshot after using it to read a file from disk cache ? #1021
-
Hello ! First, thanks for this amazing library. I was trying to use the new I saw in the documentation that calling /**
* Get the entry associated with [key].
*
* IMPORTANT: **You must** call either [Snapshot.close] or [Snapshot.closeAndEdit] when finished
* reading the snapshot. An open snapshot prevents editing the entry or deleting it on disk.
*/
operator fun get(key: String): Snapshot? After, I was looking around and I saw that in the code of For example here // Always return cached images with empty metadata as they were likely added manually.
if (snapshot.metadata.length() == 0L) {
return SourceResult(
source = snapshot.toImageSource(),
mimeType = getMimeType(url, null),
dataSource = DataSource.DISK
)
} Is it a bug or did I not understand somethink ? Can you help me ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks! And yep, this is intentional as we need to keep the disk snapshot open until it's finished being read by a |
Beta Was this translation helpful? Give feedback.
Thanks! And yep, this is intentional as we need to keep the disk snapshot open until it's finished being read by a
Decoder
. Otherwise, the file in the disk cache could be deleted while it's being decoded. It's always eventually closed here even if there's an uncaught exception.