From e0dded35c75540a94f0e7f536494376629ffc343 Mon Sep 17 00:00:00 2001 From: Stephen Aigbomian Date: Thu, 30 May 2024 01:39:46 -0700 Subject: [PATCH] Create new DiskCacheDecision class Reviewed By: oprisnik Differential Revision: D57825319 fbshipit-source-id: ee59b10ac7eedace00faf4f8dbcdd6b9b7db1ca9 --- .../producers/DiskCacheDecision.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DiskCacheDecision.kt diff --git a/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DiskCacheDecision.kt b/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DiskCacheDecision.kt new file mode 100644 index 0000000000..4593a7e053 --- /dev/null +++ b/imagepipeline/src/main/java/com/facebook/imagepipeline/producers/DiskCacheDecision.kt @@ -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? + ): 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) +}