Commit a68a8578 authored by 汪洋's avatar 汪洋

重构了GMCache: 使用类方法

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