mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
GSFileURLHandle: Remove caching functionality
This commit is contained in:
parent
a127d4ee75
commit
a1dff584a4
3 changed files with 1 additions and 105 deletions
|
@ -49,12 +49,7 @@
|
|||
{
|
||||
NSString *_path;
|
||||
NSMutableDictionary *_attributes;
|
||||
BOOL _cached;
|
||||
BOOL _didLoad;
|
||||
}
|
||||
|
||||
+ (void) _setFileCacheSize: (NSUInteger) size;
|
||||
+ (NSCache *) _fileCache;
|
||||
@end
|
||||
|
||||
/**
|
||||
|
@ -610,32 +605,9 @@ static Class NSURLHandleClass = 0;
|
|||
*/
|
||||
@implementation GSFileURLHandle
|
||||
|
||||
static NSCache *fileCache = nil;
|
||||
static NSUInteger defaultCacheSize = 4 * 1024 * 1024;
|
||||
|
||||
+ (void) _setFileCacheSize: (NSUInteger) size
|
||||
{
|
||||
[fileCache setTotalCostLimit: size];
|
||||
}
|
||||
|
||||
+ (NSCache *) _fileCache
|
||||
{
|
||||
return fileCache;
|
||||
}
|
||||
|
||||
+ (NSURLHandle*) cachedHandleForURL: (NSURL*)url
|
||||
{
|
||||
NSURLHandle *obj = nil;
|
||||
|
||||
if ([url isFileURL] == YES)
|
||||
{
|
||||
NSString *path = [url path];
|
||||
|
||||
path = [path stringByStandardizingPath];
|
||||
obj = [fileCache objectForKey: path];
|
||||
IF_NO_ARC([[obj retain] autorelease];)
|
||||
}
|
||||
return obj;
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (BOOL) canInitWithURL: (NSURL*)url
|
||||
|
@ -647,14 +619,6 @@ static NSUInteger defaultCacheSize = 4 * 1024 * 1024;
|
|||
return NO;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
fileCache = [NSCache new];
|
||||
[fileCache setName: @"org.gnustep.GSFileURLHandle.cache"];
|
||||
[fileCache setTotalCostLimit: defaultCacheSize];
|
||||
[[NSObject leakAt: &fileCache] release];
|
||||
}
|
||||
|
||||
- (NSData*) availableResourceData
|
||||
{
|
||||
if (_data != nil)
|
||||
|
@ -709,21 +673,6 @@ static NSUInteger defaultCacheSize = 4 * 1024 * 1024;
|
|||
path = [url path];
|
||||
path = [path stringByStandardizingPath];
|
||||
|
||||
_didLoad = NO;
|
||||
_cached = cached;
|
||||
if (cached == YES)
|
||||
{
|
||||
id obj;
|
||||
|
||||
obj = [fileCache objectForKey: path];
|
||||
if (obj != nil)
|
||||
{
|
||||
DESTROY(self);
|
||||
IF_NO_ARC([obj retain];)
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if ((self = [super initWithURL: url cached: cached]) != nil)
|
||||
{
|
||||
_path = [path copy];
|
||||
|
@ -741,12 +690,6 @@ static NSUInteger defaultCacheSize = 4 * 1024 * 1024;
|
|||
RELEASE(_attributes);
|
||||
_attributes = [dict mutableCopy];
|
||||
|
||||
if (_cached && !_didLoad)
|
||||
{
|
||||
[fileCache setObject: self forKey: _path cost: [d length]];
|
||||
}
|
||||
_didLoad = YES;
|
||||
|
||||
[self didLoadBytes: d loadComplete: YES];
|
||||
return d;
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed lobortis
|
||||
nisl, id suscipit nunc.
|
|
@ -1,45 +0,0 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "Testing.h"
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
@interface GSFileURLHandle : NSURLHandle
|
||||
+ (void) _setFileCacheSize: (NSUInteger) size;
|
||||
+ (NSCache *) _fileCache;
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSString *execPath;
|
||||
NSString *path;
|
||||
NSURL *url;
|
||||
NSCache *cache;
|
||||
NSData *data;
|
||||
GSFileURLHandle *fileHandle;
|
||||
Class fileHandleClass;
|
||||
|
||||
|
||||
execPath = [[NSBundle mainBundle] resourcePath];
|
||||
NSLog(@"Resource Path: %@", execPath);
|
||||
// Assuming executable is located in obj subdir
|
||||
path = [NSString stringWithFormat: @"%@/testData.txt", execPath];
|
||||
url = [NSURL fileURLWithPath: path];
|
||||
|
||||
fileHandleClass = [NSURLHandle URLHandleClassForURL: url];
|
||||
fileHandle = [[fileHandleClass alloc] initWithURL: url cached: YES];
|
||||
cache = [GSFileURLHandle _fileCache];
|
||||
|
||||
GSFileURLHandle *h = [cache objectForKey: [url path]];
|
||||
PASS(h == nil, "Cache does not store unloaded file handle");
|
||||
|
||||
data = [fileHandle loadInForeground];
|
||||
PASS(data != nil, "Data is valid");
|
||||
|
||||
h = [cache objectForKey: [url path]];
|
||||
PASS(h != nil, "Cache stores loaded file handle");
|
||||
PASS([fileHandle isEqualTo: h], "File handles are equivalent");
|
||||
|
||||
[fileHandle release];
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue