Browse Source

修改不同实例的缓存空间支持

gaosboy 12 years ago
parent
commit
6c859b9193
3 changed files with 18 additions and 7 deletions
  1. 2 2
      Kache/KHolder.h
  2. 13 1
      Kache/KHolder.m
  3. 3 4
      Kache/Kache.m

+ 2 - 2
Kache/KHolder.h

@@ -6,8 +6,6 @@
 //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 //
 
-#define Kache_Objects_Disk_Path         @"Caches/Kache_objects"
-
 #import <Foundation/Foundation.h>
 
 @class KQueue;
@@ -21,6 +19,8 @@
     NSUInteger                  size;
 }
 
+- (id)initWithToken:(NSString *)token;
+
 - (void)setValue:(id)value forKey:(NSString *)key expiredAfter:(NSInteger)duration;
 - (id)valueForKey:(NSString *)key;
 - (KObject *)objectForKey:(NSString *)key;

+ 13 - 1
Kache/KHolder.m

@@ -6,6 +6,8 @@
 //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 //
 
+#define Kache_Objects_Disk_Path         @"Caches/Kache_objects"
+
 #import "KConfig.h"
 #import "KHolder.h"
 #import "KObject.h"
@@ -50,6 +52,16 @@
 #pragma mark - init
 
 - (id)init
+{
+    self = [self initWithToken:@"_KacheDefault"];
+    if (self) {
+        return self;
+    }
+
+    return nil;
+}
+
+- (id)initWithToken:(NSString *)token
 {
     self = [super init];
     if (self) {
@@ -59,7 +71,7 @@
         
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
         NSString *libDirectory = [paths objectAtIndex:0];
-        self.path = [libDirectory stringByAppendingPathComponent:Kache_Objects_Disk_Path];
+        self.path = [libDirectory stringByAppendingPathComponent:[Kache_Objects_Disk_Path stringByAppendingPathExtension:token]];
         
         return self;
     }

+ 3 - 4
Kache/Kache.m

@@ -106,7 +106,7 @@
         self.queues = [[NSMutableDictionary alloc] init];
         self.pools = [[NSMutableDictionary alloc] init];
         
-        self.holder = [[KHolder alloc] init];
+        self.holder = [[KHolder alloc] initWithToken:aFiletoken];
         
         [self newPoolWithName:nil size:0];
         [self newQueueWithName:nil size:0];
@@ -222,7 +222,7 @@
 	NSString *libDirectory = [paths objectAtIndex:0];
 	NSString *path = @"Caches/KACHE_STORAGE_FILE_QERFCVBJKOL:";
 	if (self.filetoken) {
-		path = [path stringByAppendingString:self.filetoken];
+		path = [path stringByAppendingPathExtension:self.filetoken];
 	}
 	NSString *filePath = [libDirectory stringByAppendingPathComponent:path];
 	
@@ -231,13 +231,12 @@
 }
 
 - (void)load {
-    NSLog(@"zouni");
 	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
 	NSString *libDirectory = [paths objectAtIndex:0];
 	
 	NSString *path = @"Caches/KACHE_STORAGE_FILE_QERFCVBJKOL:";
 	if (self.filetoken) {
-		path = [path stringByAppendingString:self.filetoken];
+		path = [path stringByAppendingPathExtension:self.filetoken];
 	}
 	NSString *filePath = [libDirectory stringByAppendingPathComponent:path];