GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix the issue that previous optimization for special case (multiple s… · SDWebImage/SDWebImage@066163f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • SDWebImage/Core
    • SDImageCache.m
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎SDWebImage/Core/SDImageCache.m‎

Copy file name to clipboardExpand all lines: SDWebImage/Core/SDImageCache.m
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ - (nullable SDImageCacheToken *)queryCacheOperationForKey:(nullable NSString *)k
619619

620620
// First check the in-memory cache...
621621
UIImage *image;
622-
if (queryCacheType != SDImageCacheTypeDisk) {
622+
BOOL shouldQueryDiskOnly = (queryCacheType == SDImageCacheTypeDisk);
623+
if (!shouldQueryDiskOnly) {
623624
image = [self imageFromMemoryCacheForKey:key];
624625
}
625626

@@ -683,14 +684,19 @@ - (nullable SDImageCacheToken *)queryCacheOperationForKey:(nullable NSString *)k
683684
// the image is from in-memory cache, but need image data
684685
diskImage = image;
685686
} else if (diskData) {
687+
// the image memory cache miss, need image data and image
686688
BOOL shouldCacheToMemory = YES;
687689
if (context[SDWebImageContextStoreCacheType]) {
688690
SDImageCacheType cacheType = [context[SDWebImageContextStoreCacheType] integerValue];
689691
shouldCacheToMemory = (cacheType == SDImageCacheTypeAll || cacheType == SDImageCacheTypeMemory);
690692
}
691-
// Special case: If user query image in list for the same URL, to avoid decode and write **same** image object into disk cache multiple times, we query and check memory cache here again.
692-
if (shouldCacheToMemory && self.config.shouldCacheImagesInMemory) {
693-
diskImage = [self.memoryCache objectForKey:key];
693+
// Special case: If user query image in list for the same URL, to avoid decode and write **same** image object into disk cache multiple times, we query and check memory cache here again. See: #3523
694+
// This because disk operation can be async, previous sync check of `memory cache miss`, does not gurantee current check of `memory cache miss`
695+
if (!shouldQueryDiskSync) {
696+
// First check the in-memory cache...
697+
if (!shouldQueryDiskOnly) {
698+
diskImage = [self imageFromMemoryCacheForKey:key];
699+
}
694700
}
695701
// decode image data only if in-memory cache missed
696702
if (!diskImage) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.