Skip to content

Commit 76248d5

Browse files
romanbsdOlivier Poitrey
authored andcommitted
Cache clearing and isCached method
1 parent 097857b commit 76248d5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

SDURLCache.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@
3535
*/
3636
+ (NSString *)defaultCachePath;
3737

38+
/*
39+
* Checks if the provided URL exists in cache.
40+
*/
41+
- (BOOL)isCached:(NSURL *)url;
42+
43+
/*
44+
* Removes the cache contents.
45+
*/
46+
- (BOOL)clearCache;
47+
3848
@end

SDURLCache.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,28 @@ - (void)removeAllCachedResponses
503503
[super removeAllCachedResponses];
504504
}
505505

506+
- (BOOL)clearCache
507+
{
508+
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
509+
return [fileManager removeItemAtPath:diskCachePath error:NULL];
510+
}
511+
512+
- (BOOL)isCached:(NSURL *)url
513+
{
514+
NSURLRequest *request = [NSURLRequest requestWithURL:url];
515+
if ([super cachedResponseForRequest:request])
516+
{
517+
return YES;
518+
}
519+
NSString *cacheKey = [SDURLCache cacheKeyForURL:url];
520+
NSString *cacheFile = [diskCachePath stringByAppendingPathComponent:cacheKey];
521+
if ([[[[NSFileManager alloc] init] autorelease] fileExistsAtPath:cacheFile])
522+
{
523+
return YES;
524+
}
525+
return NO;
526+
}
527+
506528
#pragma mark NSObject
507529

508530
- (void)dealloc

0 commit comments

Comments
 (0)