Permalink
Browse files

method removeCacheEntry extended with one parameter fallbackURL to ge…

…t pathExtension like "xml",

used by manually imported objects with new import method in 0.8.1
  • Loading branch information...
1 parent cea05c9 commit 119c3c89ec43ba12c5a3e5373cf8a65d7253a797 Sebastian Grimme committed Oct 31, 2013
Showing with 33 additions and 11 deletions.
  1. +12 −6 src/shared/AFCache+Packaging.m
  2. +1 −0 src/shared/AFCache+PrivateAPI.h
  3. +20 −5 src/shared/AFCache.m
@@ -323,16 +323,22 @@ - (BOOL)importCacheableItem:(AFCacheableItem*)cacheableItem withData:(NSData*)th
- (AFCacheableItem *)importObjectForURL:(NSURL *)url data:(NSData *)data
{
- AFCacheableItem *item = [[AFCacheableItem alloc] initWithURL:url lastModified:[NSDate date] expireDate:nil];
-
- [self importCacheableItem:item withData:data];
-
- return [item autorelease];
+ AFCacheableItem *cachedItem = [self cacheableItemFromCacheStore:url];
+ if (cachedItem) {
+ return cachedItem;
+ }
+ else {
+ AFCacheableItem *item = [[AFCacheableItem alloc] initWithURL:url lastModified:[NSDate date] expireDate:nil];
+
+ [self importCacheableItem:item withData:data];
+
+ return [item autorelease];
+ }
}
- (void)purgeCacheableItemForURL:(NSURL*)url {
AFCacheableItemInfo *cacheableItemInfo = [CACHED_OBJECTS valueForKey:[url absoluteString]];
- [self removeCacheEntry:cacheableItemInfo fileOnly:NO];
+ [self removeCacheEntry:cacheableItemInfo fileOnly:NO fallbackURL:url];
}
- (void)purgePackageArchiveForURL:(NSURL*)url {
@@ -72,6 +72,7 @@
- (NSMutableDictionary*)_newCacheInfoStore;
- (BOOL)_fileExistsOrPendingForCacheableItem:(AFCacheableItem*)item;
- (void)removeCacheEntry:(AFCacheableItemInfo*)info fileOnly:(BOOL) fileOnly;
+- (void)removeCacheEntry:(AFCacheableItemInfo*)info fileOnly:(BOOL) fileOnly fallbackURL:(NSURL *)fallbackURL;
- (NSURL*)redirectURLForURL:(NSURL*)anURL;
@end
View
@@ -1012,27 +1012,42 @@ - (NSUInteger)numberOfObjectsInDiskCache {
return 0;
}
-- (void)removeCacheEntry:(AFCacheableItemInfo*)info fileOnly:(BOOL) fileOnly {
+- (void)removeCacheEntry:(AFCacheableItemInfo*)info fileOnly:(BOOL)fileOnly
+{
+ [self removeCacheEntry:info fileOnly:fileOnly fallbackURL:nil];
+}
+
+- (void)removeCacheEntry:(AFCacheableItemInfo*)info fileOnly:(BOOL) fileOnly fallbackURL:(NSURL *)fallbackURL;
+{
if (nil == info) {
return;
}
NSError *error;
-
- //NSString *filePath = [self filePath:info.filename];
+
NSString *filePath = nil;
if (self.cacheWithHashname == NO)
{
filePath = [self filePathForURL:info.request.URL];
}
else
{
- filePath = [self filePath:info.filename pathExtension:[info.request.URL pathExtension]];
+ if (fallbackURL) {
+ filePath = [self filePath:info.filename pathExtension:[fallbackURL pathExtension]];
+ }
+ else {
+ filePath = [self filePath:info.filename pathExtension:[info.request.URL pathExtension]];
+ }
}
if (YES == [[NSFileManager defaultManager] removeItemAtPath: filePath error: &error]) {
if (fileOnly==NO) {
- [CACHED_OBJECTS removeObjectForKey:[[info.request URL] absoluteString]];
+ if (fallbackURL) {
+ [CACHED_OBJECTS removeObjectForKey:[fallbackURL absoluteString]];
+ }
+ else {
+ [CACHED_OBJECTS removeObjectForKey:[[info.request URL] absoluteString]];
+ }
}
} else {
NSLog(@ "Failed to delete file for outdated cache item info %@", info);

0 comments on commit 119c3c8

Please sign in to comment.