Эх сурвалжийг харах

Merge pull request #24 from havthgem/master

Add convenience init method
Yaoyuan 9 жил өмнө
parent
commit
8a7ca7b89b
2 өөрчлөгдсөн 31 нэмэгдсэн , 0 устгасан
  1. 23 0
      YYCache/YYCache.h
  2. 8 0
      YYCache/YYCache.m

+ 23 - 0
YYCache/YYCache.h

@@ -68,6 +68,29 @@ FOUNDATION_EXPORT const unsigned char YYCacheVersionString[];
  */
 - (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
 
+/**
+ Convenience Initializers
+ Create a new instance with the specified name.
+ Multiple instances with the same name will make the cache unstable.
+ 
+ @param name  The name of the cache. It will create a dictionary with the name in
+     the app's caches dictionary for disk cache. Once initialized you should not 
+     read and write to this directory.
+ @result A new cache object, or nil if an error occurs.
+ */
++ (instancetype)cacheWithName:(NSString *)name;
+
+/**
+ Convenience Initializers
+ Create a new instance with the specified name.
+ Multiple instances with the same name will make the cache unstable.
+ 
+ @param path  Full path of a directory in which the cache will write data.
+     Once initialized you should not read and write to this directory.
+ @result A new cache object, or nil if an error occurs.
+ */
++ (instancetype)cacheWithPath:(NSString *)path;
+
 - (instancetype)init UNAVAILABLE_ATTRIBUTE;
 + (instancetype)new UNAVAILABLE_ATTRIBUTE;
 

+ 8 - 0
YYCache/YYCache.m

@@ -42,6 +42,14 @@
     return self;
 }
 
++ (instancetype)cacheWithName:(NSString *)name {
+	return [[YYCache alloc] initWithName:name];
+}
+
++ (instancetype)cacheWithPath:(NSString *)path {
+    return [[YYCache alloc] initWithPath:path];
+}
+
 - (BOOL)containsObjectForKey:(NSString *)key {
     return [_memoryCache containsObjectForKey:key] || [_diskCache containsObjectForKey:key];
 }