Skip to content

Commit

Permalink
Create new DiskCacheDecision class
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D57825319

fbshipit-source-id: ee59b10ac7eedace00faf4f8dbcdd6b9b7db1ca9
  • Loading branch information
Stephen Aigbomian authored and facebook-github-bot committed May 30, 2024
1 parent 19751f2 commit e0dded3
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.imagepipeline.producers

import com.facebook.imagepipeline.cache.BufferedDiskCache
import com.facebook.imagepipeline.request.ImageRequest
import com.facebook.imagepipeline.request.ImageRequest.CacheChoice

object DiskCacheDecision {

@JvmStatic
fun chooseDiskCacheForRequest(
imageRequest: ImageRequest,
smallDiskCache: BufferedDiskCache?,
defaultDiskCache: BufferedDiskCache?,
dynamicDiskCaches: Map<String, BufferedDiskCache>?
): BufferedDiskCache? {
if (imageRequest.cacheChoice == CacheChoice.SMALL) {
return smallDiskCache
}
if (imageRequest.cacheChoice == CacheChoice.DEFAULT) {
return defaultDiskCache
}
if (imageRequest.cacheChoice == CacheChoice.DYNAMIC && dynamicDiskCaches != null) {
val diskCacheId = imageRequest.diskCacheId
if (diskCacheId != null) {
return dynamicDiskCaches[diskCacheId]
}
}
return null
}

internal class DiskCacheDecisionNoDiskCacheChosenException(message: String?) : Exception(message)
}

0 comments on commit e0dded3

Please sign in to comment.