فهرست منبع

修复归档时无法存入的问题

gaosboy 12 سال پیش
والد
کامیت
69e9581856
2فایلهای تغییر یافته به همراه7 افزوده شده و 16 حذف شده
  1. 0 6
      Kache/KConfig.h
  2. 7 10
      Kache/KHolder.m

+ 0 - 6
Kache/KConfig.h

@@ -6,12 +6,6 @@
 //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 //
 
-// If it is set as 1 it use two level storage. Once more than
-// 100 objects stored in memory, the earliest objects will be
-// archived to disk storaged.
-#define     KACHE_AUTO_ARCH             0
-#define     KACHE_ARCH_THREHOLD_VALUE   500
-
 #define     KACHE_DEFAULT_POOL_SIZE     20
 #define     KACHE_DEFAULT_QUEUE_SIZE    10
 

+ 7 - 10
Kache/KHolder.m

@@ -182,7 +182,7 @@
 {
     KObject *object = [[KObject alloc] initWithData:value andLifeDuration:duration];
     
-    if (YES || self.archiving) {
+    if (self.archiving) {
         NSString *filePath = [self.path stringByAppendingPathComponent:key];
         [object.data writeToFile:filePath atomically:YES];
     }
@@ -191,8 +191,6 @@
         self.size += [object size];
     }
     
-    KObject *suchObject = [self objectForKey:key];
-    
     // TODO sort the key by expired time.
     [self.keys removeObject:key];
     
@@ -203,7 +201,7 @@
             NSString *tmpKey = [self.keys objectAtIndex:i];
             KObject *leftObject = [self objectForKey:tmpKey];
             // 过期时间越晚
-            if ([leftObject expiredTimestamp] <= [suchObject expiredTimestamp]) {
+            if ([leftObject expiredTimestamp] <= [object expiredTimestamp]) {
                 if (([self.keys count] - 1) == i) {
                     [self.keys addObject:key];
                 }
@@ -238,19 +236,18 @@
 
 - (KObject *)objectForKey:(NSString *)key
 {
-    if ([[self.objects allKeys] containsObject:key]) {
-        return [[KObject alloc] initWithData:[self.objects objectForKey:key]];
-    }
-    else {
+    if (! [[self.objects allKeys] containsObject:key]) {
         NSString *filePath = [self.path stringByAppendingPathComponent:key];
         if ([self.fileManager fileExistsAtPath:filePath isDirectory:NO]) {
             [self.objects setValue:[NSData dataWithContentsOfFile:filePath] forKey:key];
             [self.fileManager removeItemAtPath:filePath error:nil];
-            return [[KObject alloc] initWithData:[self.objects objectForKey:key]];
+        }
+        else {
+            return nil;
         }
     }
     
-    return nil;
+    return [[KObject alloc] initWithData:[self.objects objectForKey:key]];
 }
 
 // Convert object to NSDictionary.