mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Ensure the stars for all pointers belong to the variable rather than the type. Refs #614
This commit is contained in:
@@ -27,24 +27,24 @@
|
||||
|
||||
@implementation RKCache
|
||||
|
||||
- (id)initWithPath:(NSString*)cachePath subDirectories:(NSArray*)subDirectories
|
||||
- (id)initWithPath:(NSString *)cachePath subDirectories:(NSArray *)subDirectories
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_cachePath = [cachePath copy];
|
||||
_cacheLock = [[NSRecursiveLock alloc] init];
|
||||
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSMutableArray* pathArray = [NSMutableArray arrayWithObject:_cachePath];
|
||||
for (NSString* subDirectory in subDirectories) {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSMutableArray *pathArray = [NSMutableArray arrayWithObject:_cachePath];
|
||||
for (NSString *subDirectory in subDirectories) {
|
||||
[pathArray addObject:[_cachePath stringByAppendingPathComponent:subDirectory]];
|
||||
}
|
||||
|
||||
for (NSString* path in pathArray) {
|
||||
for (NSString *path in pathArray) {
|
||||
BOOL isDirectory = NO;
|
||||
BOOL fileExists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
|
||||
if (!fileExists) {
|
||||
NSError* error = nil;
|
||||
NSError *error = nil;
|
||||
BOOL created = [fileManager createDirectoryAtPath:path
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
@@ -73,33 +73,33 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)cachePath
|
||||
- (NSString *)cachePath
|
||||
{
|
||||
return _cachePath;
|
||||
}
|
||||
|
||||
- (NSString*)pathForCacheKey:(NSString*)cacheKey
|
||||
- (NSString *)pathForCacheKey:(NSString *)cacheKey
|
||||
{
|
||||
[_cacheLock lock];
|
||||
NSString* pathForCacheKey = [_cachePath stringByAppendingPathComponent:cacheKey];
|
||||
NSString *pathForCacheKey = [_cachePath stringByAppendingPathComponent:cacheKey];
|
||||
[_cacheLock unlock];
|
||||
RKLogTrace(@"Found cachePath '%@' for %@", pathForCacheKey, cacheKey);
|
||||
return pathForCacheKey;
|
||||
}
|
||||
|
||||
- (BOOL)hasEntry:(NSString*)cacheKey
|
||||
- (BOOL)hasEntry:(NSString *)cacheKey
|
||||
{
|
||||
[_cacheLock lock];
|
||||
BOOL hasEntry = NO;
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSString* cachePath = [self pathForCacheKey:cacheKey];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *cachePath = [self pathForCacheKey:cacheKey];
|
||||
hasEntry = [fileManager fileExistsAtPath:cachePath];
|
||||
[_cacheLock unlock];
|
||||
RKLogTrace(@"Determined hasEntry: %@ => %@", cacheKey, hasEntry ? @"YES" : @"NO");
|
||||
return hasEntry;
|
||||
}
|
||||
|
||||
- (void)writeDictionary:(NSDictionary*)dictionary withCacheKey:(NSString*)cacheKey
|
||||
- (void)writeDictionary:(NSDictionary *)dictionary withCacheKey:(NSString *)cacheKey
|
||||
{
|
||||
if (dictionary) {
|
||||
[_cacheLock lock];
|
||||
@@ -114,13 +114,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)writeData:(NSData*)data withCacheKey:(NSString*)cacheKey
|
||||
- (void)writeData:(NSData *)data withCacheKey:(NSString *)cacheKey
|
||||
{
|
||||
if (data) {
|
||||
[_cacheLock lock];
|
||||
NSString* cachePath = [self pathForCacheKey:cacheKey];
|
||||
NSString *cachePath = [self pathForCacheKey:cacheKey];
|
||||
if (cachePath) {
|
||||
NSError* error = nil;
|
||||
NSError *error = nil;
|
||||
BOOL success = [data writeToFile:cachePath options:NSDataWritingAtomic error:&error];
|
||||
if (success) {
|
||||
RKLogTrace(@"Wrote cached data to path '%@'", cachePath);
|
||||
@@ -132,11 +132,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary*)dictionaryForCacheKey:(NSString*)cacheKey
|
||||
- (NSDictionary *)dictionaryForCacheKey:(NSString *)cacheKey
|
||||
{
|
||||
[_cacheLock lock];
|
||||
NSDictionary* dictionary = nil;
|
||||
NSString* cachePath = [self pathForCacheKey:cacheKey];
|
||||
NSDictionary *dictionary = nil;
|
||||
NSString *cachePath = [self pathForCacheKey:cacheKey];
|
||||
if (cachePath) {
|
||||
dictionary = [NSDictionary dictionaryWithContentsOfFile:cachePath];
|
||||
if (dictionary) {
|
||||
@@ -151,11 +151,11 @@
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
- (NSData*)dataForCacheKey:(NSString*)cacheKey
|
||||
- (NSData *)dataForCacheKey:(NSString *)cacheKey
|
||||
{
|
||||
[_cacheLock lock];
|
||||
NSData* data = nil;
|
||||
NSString* cachePath = [self pathForCacheKey:cacheKey];
|
||||
NSData *data = nil;
|
||||
NSString *cachePath = [self pathForCacheKey:cacheKey];
|
||||
if (cachePath) {
|
||||
data = [NSData dataWithContentsOfFile:cachePath];
|
||||
if (data) {
|
||||
@@ -168,37 +168,37 @@
|
||||
return data;
|
||||
}
|
||||
|
||||
- (void)invalidateEntry:(NSString*)cacheKey
|
||||
- (void)invalidateEntry:(NSString *)cacheKey
|
||||
{
|
||||
[_cacheLock lock];
|
||||
RKLogDebug(@"Invalidating cache entry for '%@'", cacheKey);
|
||||
NSString* cachePath = [self pathForCacheKey:cacheKey];
|
||||
NSString *cachePath = [self pathForCacheKey:cacheKey];
|
||||
if (cachePath) {
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
[fileManager removeItemAtPath:cachePath error:NULL];
|
||||
RKLogTrace(@"Removed cache entry at path '%@' for '%@'", cachePath, cacheKey);
|
||||
}
|
||||
[_cacheLock unlock];
|
||||
}
|
||||
|
||||
- (void)invalidateSubDirectory:(NSString*)subDirectory
|
||||
- (void)invalidateSubDirectory:(NSString *)subDirectory
|
||||
{
|
||||
[_cacheLock lock];
|
||||
if (_cachePath && subDirectory) {
|
||||
NSString* subDirectoryPath = [_cachePath stringByAppendingPathComponent:subDirectory];
|
||||
NSString *subDirectoryPath = [_cachePath stringByAppendingPathComponent:subDirectory];
|
||||
RKLogInfo(@"Invalidating cache at path: %@", subDirectoryPath);
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
BOOL isDirectory = NO;
|
||||
BOOL fileExists = [fileManager fileExistsAtPath:subDirectoryPath isDirectory:&isDirectory];
|
||||
|
||||
if (fileExists && isDirectory) {
|
||||
NSError* error = nil;
|
||||
NSArray* cacheEntries = [fileManager contentsOfDirectoryAtPath:subDirectoryPath error:&error];
|
||||
NSError *error = nil;
|
||||
NSArray *cacheEntries = [fileManager contentsOfDirectoryAtPath:subDirectoryPath error:&error];
|
||||
|
||||
if (nil == error) {
|
||||
for (NSString* cacheEntry in cacheEntries) {
|
||||
NSString* cacheEntryPath = [subDirectoryPath stringByAppendingPathComponent:cacheEntry];
|
||||
for (NSString *cacheEntry in cacheEntries) {
|
||||
NSString *cacheEntryPath = [subDirectoryPath stringByAppendingPathComponent:cacheEntry];
|
||||
[fileManager removeItemAtPath:cacheEntryPath error:&error];
|
||||
if (nil != error) {
|
||||
RKLogError(@"Failed to delete cache entry for file: %@", cacheEntryPath);
|
||||
@@ -217,18 +217,18 @@
|
||||
[_cacheLock lock];
|
||||
if (_cachePath) {
|
||||
RKLogInfo(@"Invalidating cache at path: %@", _cachePath);
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
BOOL isDirectory = NO;
|
||||
BOOL fileExists = [fileManager fileExistsAtPath:_cachePath isDirectory:&isDirectory];
|
||||
|
||||
if (fileExists && isDirectory) {
|
||||
NSError* error = nil;
|
||||
NSArray* cacheEntries = [fileManager contentsOfDirectoryAtPath:_cachePath error:&error];
|
||||
NSError *error = nil;
|
||||
NSArray *cacheEntries = [fileManager contentsOfDirectoryAtPath:_cachePath error:&error];
|
||||
|
||||
if (nil == error) {
|
||||
for (NSString* cacheEntry in cacheEntries) {
|
||||
NSString* cacheEntryPath = [_cachePath stringByAppendingPathComponent:cacheEntry];
|
||||
for (NSString *cacheEntry in cacheEntries) {
|
||||
NSString *cacheEntryPath = [_cachePath stringByAppendingPathComponent:cacheEntry];
|
||||
[fileManager removeItemAtPath:cacheEntryPath error:&error];
|
||||
if (nil != error) {
|
||||
RKLogError(@"Failed to delete cache entry for file: %@", cacheEntryPath);
|
||||
|
||||
Reference in New Issue
Block a user