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
DreamPiggy
7 years ago
Commit
ad02e3eaaede2df11e419fd4a35f35db07abb971
1 parent
47b77b74
Fix CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF warning
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
17 deletions
SDWebImage/SDImageCache.m
SDWebImage/SDImageCache.m
View file @
ad02e3e
...
...
@@ -26,13 +26,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
@property
(
strong
,
nonatomic
,
nonnull
)
NSString
*
diskCachePath
;
@property
(
strong
,
nonatomic
,
nullable
)
NSMutableArray
<
NSString
*>
*
customPaths
;
@property
(
strong
,
nonatomic
,
nullable
)
dispatch_queue_t
ioQueue
;
@property
(
strong
,
nonatomic
,
nonnull
)
NSFileManager
*
fileManager
;
@end
@implementation
SDImageCache
{
NSFileManager
*
_fileManager
;
}
@implementation
SDImageCache
#pragma mark - Singleton, init, dealloc
...
...
@@ -224,8 +223,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
return
;
}
if
(
!
[
_fileManager
fileExistsAtPath
:
_diskCachePath
])
{
[
_fileManager
createDirectoryAtPath
:
_diskCachePath
withIntermediateDirectories
:
YES
attributes
:
nil
error
:
NULL
];
if
(
!
[
self
.
fileManager
fileExistsAtPath
:
_diskCachePath
])
{
[
self
.
fileManager
createDirectoryAtPath
:
_diskCachePath
withIntermediateDirectories
:
YES
attributes
:
nil
error
:
NULL
];
}
// get cache Path for image key
...
...
@@ -271,12 +270,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
if
(
!
key
)
{
return
NO
;
}
BOOL
exists
=
[
_
fileManager
fileExistsAtPath
:[
self
defaultCachePathForKey
:
key
]];
BOOL
exists
=
[
self
.
fileManager
fileExistsAtPath
:[
self
defaultCachePathForKey
:
key
]];
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
// checking the key with and without the extension
if
(
!
exists
)
{
exists
=
[
_
fileManager
fileExistsAtPath
:[
self
defaultCachePathForKey
:
key
].
stringByDeletingPathExtension
];
exists
=
[
self
.
fileManager
fileExistsAtPath
:[
self
defaultCachePathForKey
:
key
].
stringByDeletingPathExtension
];
}
return
exists
;
...
...
@@ -447,7 +446,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
if
(
fromDisk
)
{
dispatch_async
(
self
.
ioQueue
,
^
{
[
_
fileManager
removeItemAtPath
:[
self
defaultCachePathForKey
:
key
]
error
:
nil
];
[
self
.
fileManager
removeItemAtPath
:[
self
defaultCachePathForKey
:
key
]
error
:
nil
];
if
(
completion
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
...
...
@@ -487,8 +486,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
-
(
void
)
clearDiskOnCompletion
:
(
nullable
SDWebImageNoParamsBlock
)
completion
{
dispatch_async
(
self
.
ioQueue
,
^
{
[
_fileManager
removeItemAtPath
:
self
.
diskCachePath
error
:
nil
];
[
_fileManager
createDirectoryAtPath
:
self
.
diskCachePath
[
self
.
fileManager
removeItemAtPath
:
self
.
diskCachePath
error
:
nil
];
[
self
.
fileManager
createDirectoryAtPath
:
self
.
diskCachePath
withIntermediateDirectories
:
YES
attributes
:
nil
error
:
NULL
];
...
...
@@ -511,7 +510,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
NSArray
<
NSString
*>
*
resourceKeys
=
@[
NSURLIsDirectoryKey
,
NSURLContentModificationDateKey
,
NSURLTotalFileAllocatedSizeKey
];
// This enumerator prefetches useful properties for our cache files.
NSDirectoryEnumerator
*
fileEnumerator
=
[
_
fileManager
enumeratorAtURL
:
diskCacheURL
NSDirectoryEnumerator
*
fileEnumerator
=
[
self
.
fileManager
enumeratorAtURL
:
diskCacheURL
includingPropertiesForKeys
:
resourceKeys
options
:
NSDirectoryEnumerationSkipsHiddenFiles
errorHandler
:
NULL
];
...
...
@@ -548,7 +547,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
}
for
(
NSURL
*
fileURL
in
urlsToDelete
)
{
[
_
fileManager
removeItemAtURL
:
fileURL
error
:
nil
];
[
self
.
fileManager
removeItemAtURL
:
fileURL
error
:
nil
];
}
// If our remaining disk cache exceeds a configured maximum size, perform a second
...
...
@@ -565,7 +564,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
// Delete files until we fall below our desired cache size.
for
(
NSURL
*
fileURL
in
sortedFiles
)
{
if
([
_
fileManager
removeItemAtURL
:
fileURL
error
:
nil
])
{
if
([
self
.
fileManager
removeItemAtURL
:
fileURL
error
:
nil
])
{
NSDictionary
<
NSString
*
,
id
>
*
resourceValues
=
cacheFiles
[
fileURL
];
NSNumber
*
totalAllocatedSize
=
resourceValues
[
NSURLTotalFileAllocatedSizeKey
];
currentCacheSize
-=
totalAllocatedSize
.
unsignedIntegerValue
;
...
...
@@ -611,10 +610,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
-
(
NSUInteger
)
getSize
{
__block
NSUInteger
size
=
0
;
dispatch_sync
(
self
.
ioQueue
,
^
{
NSDirectoryEnumerator
*
fileEnumerator
=
[
_
fileManager
enumeratorAtPath
:
self
.
diskCachePath
];
NSDirectoryEnumerator
*
fileEnumerator
=
[
self
.
fileManager
enumeratorAtPath
:
self
.
diskCachePath
];
for
(
NSString
*
fileName
in
fileEnumerator
)
{
NSString
*
filePath
=
[
self
.
diskCachePath
stringByAppendingPathComponent
:
fileName
];
NSDictionary
<
NSString
*
,
id
>
*
attrs
=
[
_
fileManager
attributesOfItemAtPath
:
filePath
error
:
nil
];
NSDictionary
<
NSString
*
,
id
>
*
attrs
=
[
self
.
fileManager
attributesOfItemAtPath
:
filePath
error
:
nil
];
size
+=
[
attrs
fileSize
];
}
});
...
...
@@ -624,7 +623,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
-
(
NSUInteger
)
getDiskCount
{
__block
NSUInteger
count
=
0
;
dispatch_sync
(
self
.
ioQueue
,
^
{
NSDirectoryEnumerator
*
fileEnumerator
=
[
_
fileManager
enumeratorAtPath
:
self
.
diskCachePath
];
NSDirectoryEnumerator
*
fileEnumerator
=
[
self
.
fileManager
enumeratorAtPath
:
self
.
diskCachePath
];
count
=
fileEnumerator
.
allObjects
.
count
;
});
return
count
;
...
...
@@ -637,7 +636,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
NSUInteger
fileCount
=
0
;
NSUInteger
totalSize
=
0
;
NSDirectoryEnumerator
*
fileEnumerator
=
[
_
fileManager
enumeratorAtURL
:
diskCacheURL
NSDirectoryEnumerator
*
fileEnumerator
=
[
self
.
fileManager
enumeratorAtURL
:
diskCacheURL
includingPropertiesForKeys
:@[
NSFileSize
]
options
:
NSDirectoryEnumerationSkipsHiddenFiles
errorHandler
:
NULL
];
...
...
Please
register
or
login
to post a comment