Commit a68a8578 authored by 汪洋's avatar 汪洋

重构了GMCache: 使用类方法

parent 83609bed
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
CLASSPREFIX = GM; CLASSPREFIX = GM;
LastUpgradeCheck = 0720; LastUpgradeCheck = 0920;
ORGANIZATIONNAME = wangyang; ORGANIZATIONNAME = wangyang;
TargetAttributes = { TargetAttributes = {
6003F5AD195388D20070C39A = { 6003F5AD195388D20070C39A = {
...@@ -453,19 +453,30 @@ ...@@ -453,19 +453,30 @@
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1", "DEBUG=1",
...@@ -493,18 +504,29 @@ ...@@ -493,18 +504,29 @@
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES; COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNDECLARED_SELECTOR = YES;
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0720" LastUpgradeVersion = "0920"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
<TestableReference <TestableReference
...@@ -55,6 +56,7 @@ ...@@ -55,6 +56,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// //
#import "GMViewController.h" #import "GMViewController.h"
#import <GMCache/GMCache-umbrella.h> @import GMCache;
@interface GMViewController () @interface GMViewController ()
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
[[WMCacheService sharedInstance] storeObjectAtDiskWithkey:@"key" object:@1]; [GMCache storeObjectAtDiskWithkey:@"key" object:@1];
NSNumber *num = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:@"key"]; NSNumber *num = [GMCache fetchObjectAtDiskWithkey:@"key"];
NSLog(@"%@", num.stringValue); NSLog(@"%@", num.stringValue);
} }
......
use_frameworks! use_frameworks!
platform :ios, '8.0'
target 'GMCache_Example' do target 'GMCache_Example' do
pod 'GMCache', :path => '../' pod 'GMCache', :path => '../'
...@@ -8,4 +8,4 @@ target 'GMCache_Example' do ...@@ -8,4 +8,4 @@ target 'GMCache_Example' do
end end
end end
\ No newline at end of file
PODS: PODS:
- GMCache (0.1.1): - GMCache (0.1.2):
- TMCache (~> 2.1.0) - TMCache (= 2.1.0)
- TMCache (2.1.0) - TMCache (2.1.0)
DEPENDENCIES: DEPENDENCIES:
...@@ -11,9 +11,9 @@ EXTERNAL SOURCES: ...@@ -11,9 +11,9 @@ EXTERNAL SOURCES:
:path: ../ :path: ../
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: 3ea7c69465cc70a4f8c4a58eddf3775b83fab741 GMCache: ab03b092a8d0692393af66c11c5e1cd82fcb6ead
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: 58e501ebf3387a7de685a2862f8cd523abeebbb2 PODFILE CHECKSUM: 8d482f956ed77b240df3be8144ac3958c903d882
COCOAPODS: 1.3.1 COCOAPODS: 1.4.0
...@@ -10,15 +10,13 @@ Pod::Spec.new do |s| ...@@ -10,15 +10,13 @@ Pod::Spec.new do |s|
s.name = "GMCache" s.name = "GMCache"
s.version = "0.1.2" s.version = "0.1.2"
s.summary = "缓存" s.summary = "缓存"
s.homepage = "http://git.gengmei.cc/gengmeiios/GMCache" s.homepage = "http://git.wanmeizhensuo.com/gengmeiios/GMCache"
s.license = 'MIT' s.license = 'MIT'
s.author = { "wangyang" => "wangyang@wanmeizhensuo.com" } s.author = { "wangyang" => "wangyang@wanmeizhensuo.com" }
s.source = { :git => "git@git.wanmeizhensuo.com:gengmeiios/GMCache.git", :tag => s.version.to_s } s.source = { :git => "git@git.wanmeizhensuo.com:gengmeiios/GMCache.git", :tag => s.version.to_s }
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.source_files = 'GMCache/Classes/**/*' s.source_files = 'GMCache/Classes/**/*'
s.dependency 'TMCache', '2.1.0'
s.public_header_files = 'GMCache/Classes/WMCacheService.h'
s.dependency 'TMCache','~> 2.1.0'
end end
// //
// CacheService.h // GMCache.h
// Gengmei // Gengmei
// //
// Created by Thierry on 1/5/15. // Created by Thierry on 1/5/15.
...@@ -9,105 +9,73 @@ ...@@ -9,105 +9,73 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <TMCache/TMCache.h> #import <TMCache/TMCache.h>
typedef NS_ENUM(NSUInteger, WMCacheMethod) { @interface GMCache : NSObject
WMCacheDiskMethod = 1, #pragma mark - 异步磁盘读写操作
WMCacheMemoryMethod
};
@interface WMCacheService : NSObject
@property (nonatomic,strong) NSString * urlCommonString;
+ (instancetype )sharedInstance;
/**
* @brief 异步磁盘读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/ /*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtDiskWithkey:(NSString *)key + (void)storeObjectAtDiskWithkey:(NSString *)key
object:(id <NSCoding>)object object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
/*** @brief 给特定的键,标记缓存数据并缓存*/ /*** @brief 给特定的键,标记缓存数据并缓存*/
- (void)fetchObjectAtDiskWithkey:(NSString *)key + (void)fetchObjectAtDiskWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
/*** @brief 删除特定的键,对应的缓存数据*/ /*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtDiskWithkey:(NSString *)key + (void)removeObjectAtDiskWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
/*** @brief 清空所有的缓存数据*/ /*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block; + (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block;
/**
* @brief 同步磁盘读写操作
*/
#pragma mark - 同步磁盘读写操作
/*** @brief 由对应的键获取对应的缓存数据*/ /*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtDiskWithkey:(NSString *)key + (void)storeObjectAtDiskWithkey:(NSString *)key
object:(id <NSCoding>)object; object:(id <NSCoding>)object;
/*** @brief 给特定的键,标记缓存数据并缓存*/ /*** @brief 给特定的键,标记缓存数据并缓存*/
- (id)fetchObjectAtDiskWithkey:(NSString *)key; + (id)fetchObjectAtDiskWithkey:(NSString *)key;
/*** @brief 删除特定的键,对应的缓存数据*/ /*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtDiskWithkey:(NSString *)key; + (void)removeObjectAtDiskWithkey:(NSString *)key;
/*** @brief 清空所有的缓存数据*/ /*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtDisk; + (void)removeAllObjectsAtDisk;
#pragma mark - 异步内存读写操作
/**
* @brief 异步内存读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/ /*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtMemoryWithkey:(NSString *)key + (void)storeObjectAtMemoryWithkey:(NSString *)key
object:(id <NSCoding>)object object:(id <NSCoding>)object
block:(TMMemoryCacheObjectBlock)block; block:(TMMemoryCacheObjectBlock)block;
/*** @brief 给特定的键,标记缓存数据并缓存*/ /*** @brief 给特定的键,标记缓存数据并缓存*/
- (void)fetchObjectAtMemoryWithkey:(NSString *)key + (void)fetchObjectAtMemoryWithkey:(NSString *)key
block:(TMMemoryCacheObjectBlock)block; block:(TMMemoryCacheObjectBlock)block;
/*** @brief 删除特定的键,对应的缓存数据*/ /*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtMemoryWithkey:(NSString *)key + (void)removeObjectAtMemoryWithkey:(NSString *)key
block:(TMMemoryCacheObjectBlock)block; block:(TMMemoryCacheObjectBlock)block;
/*** @brief 清空所有的缓存数据*/ /*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block; + (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block;
/** #pragma mark - 同步内存读写操作
* @brief 同步内存读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/ /*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtMemoryWithkey:(NSString *)key + (void)storeObjectAtMemoryWithkey:(NSString *)key
object:(id)object; object:(id)object;
/*** @brief 给特定的键,标记缓存数据并缓存*/ /*** @brief 给特定的键,标记缓存数据并缓存*/
- (id)fetchObjectAtMemoryWithkey:(NSString *)key; + (id)fetchObjectAtMemoryWithkey:(NSString *)key;
/*** @brief 删除特定的键,对应的缓存数据*/ /*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtMemoryWithkey:(NSString *)key; + (void)removeObjectAtMemoryWithkey:(NSString *)key;
/*** @brief 清空所有的缓存数据*/ /*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtMemory; + (void)removeAllObjectsAtMemory;
#pragma mark - 这里将数据缓存到Ducument目录下
/** #pragma mark - 这里将数据缓存到Ducument目录下。异步
* @brief 异步磁盘读写操作 + (void)storeObjectAtDucmentPathWithkey:(NSString *)key
*/
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
- (void)fetchObjectAtDucmentPathWithkey:(NSString *)key + (void)fetchObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key + (void)removeObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block; block:(TMDiskCacheObjectBlock)block;
- (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block; + (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block;
/** #pragma mark - 这里将数据缓存到Ducument目录下。同步内存读写操作
* @brief 同步内存读写操作 + (void)storeObjectAtDucmentPathWithkey:(NSString *)key
*/
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object; object:(id <NSCoding>)object;
- (id)fetchObjectAtDucmentPathWithkey:(NSString *)key; + (id)fetchObjectAtDucmentPathWithkey:(NSString *)key;
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key; + (void)removeObjectAtDucmentPathWithkey:(NSString *)key;
- (void)removeAllObjectsAtDucmentPath; + (void)removeAllObjectsAtDucmentPath;
@end @end
// //
// CacheService.m // GMCache.m
// Gengmei // Gengmei
// //
// Created by Thierry on 1/5/15. // Created by Thierry on 1/5/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved. // Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
// //
#import "WMCacheService.h" #import "GMCache.h"
#import "WMDocumentCache.h" @interface WMDocumentCache : TMCache
static WMCacheService *sharedManager = nil; @end
@implementation GMCache
@implementation WMCacheService + (void)storeObjectAtDiskWithkey:(NSString *)key object:(id <NSCoding>)object block:(TMDiskCacheObjectBlock)block{
+ (instancetype)sharedInstance{
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate,^{
sharedManager = [[WMCacheService alloc]init];
});
return sharedManager;
}
- (void)storeObjectAtDiskWithkey:(NSString *)key object:(id <NSCoding>)object block:(TMDiskCacheObjectBlock)block{
[[TMCache sharedCache].diskCache setObject:object forKey:key block:block]; [[TMCache sharedCache].diskCache setObject:object forKey:key block:block];
} }
- (void)fetchObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{ + (void)fetchObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{
[[TMCache sharedCache].diskCache objectForKey:key block:block]; [[TMCache sharedCache].diskCache objectForKey:key block:block];
} }
- (void)removeObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{ + (void)removeObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{
[[TMCache sharedCache].diskCache removeObjectForKey:key block:block]; [[TMCache sharedCache].diskCache removeObjectForKey:key block:block];
} }
- (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block{ + (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block{
[[TMCache sharedCache].diskCache removeAllObjects:block]; [[TMCache sharedCache].diskCache removeAllObjects:block];
} }
+ (void)storeObjectAtDiskWithkey:(NSString *)key object:(id <NSCoding>)object{
- (void)storeObjectAtDiskWithkey:(NSString *)key object:(id <NSCoding>)object{
[[TMCache sharedCache].diskCache setObject:object forKey:key]; [[TMCache sharedCache].diskCache setObject:object forKey:key];
} }
- (id)fetchObjectAtDiskWithkey:(NSString *)key{
+ (id)fetchObjectAtDiskWithkey:(NSString *)key{
return [[TMCache sharedCache].diskCache objectForKey:key]; return [[TMCache sharedCache].diskCache objectForKey:key];
} }
- (void)removeObjectAtDiskWithkey:(NSString *)key{
+ (void)removeObjectAtDiskWithkey:(NSString *)key{
[[TMCache sharedCache].diskCache removeObjectForKey:key]; [[TMCache sharedCache].diskCache removeObjectForKey:key];
} }
- (void)removeAllObjectsAtDisk{
+ (void)removeAllObjectsAtDisk{
[[TMCache sharedCache].diskCache removeAllObjects]; [[TMCache sharedCache].diskCache removeAllObjects];
} }
+ (void)storeObjectAtMemoryWithkey:(NSString *)key object:(id <NSCoding>)object block:(TMMemoryCacheObjectBlock)block{
- (void)storeObjectAtMemoryWithkey:(NSString *)key object:(id <NSCoding>)object block:(TMMemoryCacheObjectBlock)block{
[[TMCache sharedCache].memoryCache setObject:object forKey:key block:block]; [[TMCache sharedCache].memoryCache setObject:object forKey:key block:block];
} }
- (void)fetchObjectAtMemoryWithkey:(NSString *)key block:(TMMemoryCacheObjectBlock)block{
+ (void)fetchObjectAtMemoryWithkey:(NSString *)key block:(TMMemoryCacheObjectBlock)block{
[[TMCache sharedCache].memoryCache objectForKey:key block:block]; [[TMCache sharedCache].memoryCache objectForKey:key block:block];
} }
- (void)removeObjectAtMemoryWithkey:(NSString *)key block:(TMMemoryCacheObjectBlock)block{
[[TMCache sharedCache].memoryCache removeObjectForKey:key block:block];
+ (void)removeObjectAtMemoryWithkey:(NSString *)key block:(TMMemoryCacheObjectBlock)block{
[[TMCache sharedCache].memoryCache removeObjectForKey:key block:block];
} }
- (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block{
+ (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block{
[[TMCache sharedCache].memoryCache removeAllObjects:block]; [[TMCache sharedCache].memoryCache removeAllObjects:block];
} }
+ (void)storeObjectAtMemoryWithkey:(NSString *)key object:(id)object{
- (void)storeObjectAtMemoryWithkey:(NSString *)key object:(id)object{
[[TMCache sharedCache].memoryCache setObject:object forKey:key]; [[TMCache sharedCache].memoryCache setObject:object forKey:key];
} }
- (id)fetchObjectAtMemoryWithkey:(NSString *)key{
+ (id)fetchObjectAtMemoryWithkey:(NSString *)key{
return [[TMCache sharedCache].memoryCache objectForKey:key]; return [[TMCache sharedCache].memoryCache objectForKey:key];
} }
- (void)removeObjectAtMemoryWithkey:(NSString *)key{
+ (void)removeObjectAtMemoryWithkey:(NSString *)key{
[[TMCache sharedCache].memoryCache removeObjectForKey:key]; [[TMCache sharedCache].memoryCache removeObjectForKey:key];
} }
- (void)removeAllObjectsAtMemory{
+ (void)removeAllObjectsAtMemory{
[[TMCache sharedCache].memoryCache removeAllObjects]; [[TMCache sharedCache].memoryCache removeAllObjects];
} }
+ (void)storeObjectAtDucmentPathWithkey:(NSString *)key
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block{ block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache setObject:object forKey:key block:block]; [[WMDocumentCache sharedCache].diskCache setObject:object forKey:key block:block];
} }
- (void)fetchObjectAtDucmentPathWithkey:(NSString *)key
+ (void)fetchObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block{ block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache objectForKey:key block:block]; [[WMDocumentCache sharedCache].diskCache objectForKey:key block:block];
} }
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key
+ (void)removeObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block{ block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache removeObjectForKey:key block:block]; [[WMDocumentCache sharedCache].diskCache removeObjectForKey:key block:block];
} }
- (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block{
+ (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block{
[[WMDocumentCache sharedCache].diskCache removeAllObjects:block]; [[WMDocumentCache sharedCache].diskCache removeAllObjects:block];
} }
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key + (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object{ object:(id <NSCoding>)object{
[[WMDocumentCache sharedCache].diskCache setObject:object forKey:key]; [[WMDocumentCache sharedCache].diskCache setObject:object forKey:key];
} }
- (id)fetchObjectAtDucmentPathWithkey:(NSString *)key{
return [[WMDocumentCache sharedCache].diskCache objectForKey:key]; + (id)fetchObjectAtDucmentPathWithkey:(NSString *)key{
return [[WMDocumentCache sharedCache].diskCache objectForKey:key];
} }
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key{
+ (void)removeObjectAtDucmentPathWithkey:(NSString *)key{
[[WMDocumentCache sharedCache].diskCache removeObjectForKey:key]; [[WMDocumentCache sharedCache].diskCache removeObjectForKey:key];
} }
- (void)removeAllObjectsAtDucmentPath{
+ (void)removeAllObjectsAtDucmentPath{
[[WMDocumentCache sharedCache].diskCache removeAllObjects]; [[WMDocumentCache sharedCache].diskCache removeAllObjects];
} }
@end @end
NSString * const WMCacheSharedName = @"WMCacheShared";
@implementation WMDocumentCache
+ (instancetype)sharedCache{
static id cache;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
cache = [[self alloc] initWithName:WMCacheSharedName rootPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
});
return cache;
}
@end
//
// WMCache.h
// Gengmei
//
// Created by Sean Lee on 7/23/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import <TMCache/TMCache.h>
@interface WMDocumentCache : TMCache
@end
//
// WMCache.m
// Gengmei
//
// Created by Sean Lee on 7/23/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMDocumentCache.h"
NSString * const WMCacheSharedName = @"WMCacheShared";
@implementation WMDocumentCache
+ (instancetype)sharedCache{
static id cache;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
cache = [[self alloc] initWithName:WMCacheSharedName rootPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
});
return cache;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment