Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
yh_sdwebimage
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Nebil Kriedi
12 years ago
Commit
fbf14d2e163eb9a8c27bdc8983ae51a2514db977
1 parent
ae57215c
Prefetching file properties in the disk cleaning enumerator
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
SDWebImage/SDImageCache.m
SDWebImage/SDImageCache.m
View file @
fbf14d2
...
...
@@ -256,14 +256,29 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
dispatch_async
(
self
.
ioQueue
,
^
{
NSDate
*
expirationDate
=
[
NSDate
dateWithTimeIntervalSinceNow
:
-
self
.
maxCacheAge
];
NSDirectoryEnumerator
*
fileEnumerator
=
[[
NSFileManager
defaultManager
]
enumeratorAtPath
:
self
.
diskCachePath
];
for
(
NSString
*
fileName
in
fileEnumerator
)
// convert NSString path to NSURL path
NSURL
*
diskCacheURL
=
[
NSURL
fileURLWithPath
:
self
.
diskCachePath
isDirectory
:
YES
];
// build an enumerator by also prefetching file properties we want to read
NSDirectoryEnumerator
*
fileEnumerator
=
[[
NSFileManager
defaultManager
]
enumeratorAtURL
:
diskCacheURL
includingPropertiesForKeys
:@[
NSURLIsDirectoryKey
,
NSURLContentModificationDateKey
]
options
:
NSDirectoryEnumerationSkipsHiddenFiles
errorHandler
:
NULL
];
for
(
NSURL
*
fileURL
in
fileEnumerator
)
{
NSString
*
filePath
=
[
self
.
diskCachePath
stringByAppendingPathComponent
:
fileName
];
NSDictionary
*
attrs
=
[[
NSFileManager
defaultManager
]
attributesOfItemAtPath
:
filePath
error
:
nil
];
if
([[[
attrs
fileModificationDate
]
laterDate
:
expirationDate
]
isEqualToDate
:
expirationDate
])
// skip folder
NSNumber
*
isDirectory
;
[
fileURL
getResourceValue
:
&
isDirectory
forKey
:
NSURLIsDirectoryKey
error
:
NULL
];
if
([
isDirectory
boolValue
])
{
[[
NSFileManager
defaultManager
]
removeItemAtPath
:
filePath
error
:
nil
];
continue
;
}
// compare file date with the max age
NSDate
*
fileModificationDate
;
[
fileURL
getResourceValue
:
&
fileModificationDate
forKey
:
NSURLContentModificationDateKey
error
:
NULL
];
if
([[
fileModificationDate
laterDate
:
expirationDate
]
isEqualToDate
:
expirationDate
])
{
[[
NSFileManager
defaultManager
]
removeItemAtURL
:
fileURL
error
:
nil
];
}
}
});
...
...
Please
register
or
login
to post a comment