Commit 3d514a17 authored by 汪洋's avatar 汪洋

save

parent fedb23e9
//
// CacheService.h
// Gengmei
//
// Created by Thierry on 1/5/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#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 异步磁盘读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtDiskWithkey:(NSString *)key
object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block;
/*** @brief 给特定的键,标记缓存数据并缓存*/
- (void)fetchObjectAtDiskWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block;
/*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtDiskWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block;
/*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block;
/**
* @brief 同步磁盘读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtDiskWithkey:(NSString *)key
object:(id <NSCoding>)object;
/*** @brief 给特定的键,标记缓存数据并缓存*/
- (id)fetchObjectAtDiskWithkey:(NSString *)key;
/*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtDiskWithkey:(NSString *)key;
/*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtDisk;
/**
* @brief 异步内存读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtMemoryWithkey:(NSString *)key
object:(id <NSCoding>)object
block:(TMMemoryCacheObjectBlock)block;
/*** @brief 给特定的键,标记缓存数据并缓存*/
- (void)fetchObjectAtMemoryWithkey:(NSString *)key
block:(TMMemoryCacheObjectBlock)block;
/*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtMemoryWithkey:(NSString *)key
block:(TMMemoryCacheObjectBlock)block;
/*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block;
/**
* @brief 同步内存读写操作
*/
/*** @brief 由对应的键获取对应的缓存数据*/
- (void)storeObjectAtMemoryWithkey:(NSString *)key
object:(id)object;
/*** @brief 给特定的键,标记缓存数据并缓存*/
- (id)fetchObjectAtMemoryWithkey:(NSString *)key;
/*** @brief 删除特定的键,对应的缓存数据*/
- (void)removeObjectAtMemoryWithkey:(NSString *)key;
/*** @brief 清空所有的缓存数据*/
- (void)removeAllObjectsAtMemory;
#pragma mark - 这里将数据缓存到Ducument目录下
/**
* @brief 异步磁盘读写操作
*/
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block;
- (void)fetchObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block;
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block;
- (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block;
/**
* @brief 同步内存读写操作
*/
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object;
- (id)fetchObjectAtDucmentPathWithkey:(NSString *)key;
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key;
- (void)removeAllObjectsAtDucmentPath;
@end
//
// CacheService.m
// Gengmei
//
// Created by Thierry on 1/5/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMCacheService.h"
#import "WMDocumentCache.h"
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{
[[TMCache sharedCache].diskCache setObject:object forKey:key block:block];
}
- (void)fetchObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{
[[TMCache sharedCache].diskCache objectForKey:key block:block];
}
- (void)removeObjectAtDiskWithkey:(NSString *)key block:(TMDiskCacheObjectBlock)block{
[[TMCache sharedCache].diskCache removeObjectForKey:key block:block];
}
- (void)removeAllObjectsAtDiskWithBlock:(TMDiskCacheBlock)block{
[[TMCache sharedCache].diskCache removeAllObjects:block];
}
- (void)storeObjectAtDiskWithkey:(NSString *)key object:(id <NSCoding>)object{
[[TMCache sharedCache].diskCache setObject:object forKey:key];
}
- (id)fetchObjectAtDiskWithkey:(NSString *)key{
return [[TMCache sharedCache].diskCache objectForKey:key];
}
- (void)removeObjectAtDiskWithkey:(NSString *)key{
[[TMCache sharedCache].diskCache removeObjectForKey:key];
}
- (void)removeAllObjectsAtDisk{
[[TMCache sharedCache].diskCache removeAllObjects];
}
- (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{
[[TMCache sharedCache].memoryCache objectForKey:key block:block];
}
- (void)removeObjectAtMemoryWithkey:(NSString *)key block:(TMMemoryCacheObjectBlock)block{
[[TMCache sharedCache].memoryCache removeObjectForKey:key block:block];
}
- (void)removeAllObjectsAtMemoryWithBlock:(TMMemoryCacheBlock)block{
[[TMCache sharedCache].memoryCache removeAllObjects:block];
}
- (void)storeObjectAtMemoryWithkey:(NSString *)key object:(id)object{
[[TMCache sharedCache].memoryCache setObject:object forKey:key];
}
- (id)fetchObjectAtMemoryWithkey:(NSString *)key{
return [[TMCache sharedCache].memoryCache objectForKey:key];
}
- (void)removeObjectAtMemoryWithkey:(NSString *)key{
[[TMCache sharedCache].memoryCache removeObjectForKey:key];
}
- (void)removeAllObjectsAtMemory{
[[TMCache sharedCache].memoryCache removeAllObjects];
}
- (void)storeObjectAtDucmentPathWithkey:(NSString *)key
object:(id <NSCoding>)object
block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache setObject:object forKey:key block:block];
}
- (void)fetchObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache objectForKey:key block:block];
}
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key
block:(TMDiskCacheObjectBlock)block{
[[WMDocumentCache sharedCache].diskCache removeObjectForKey:key block:block];
}
- (void)removeAllObjectsAtDucmentPathWithBlock:(TMDiskCacheBlock)block{
[[WMDocumentCache sharedCache].diskCache removeAllObjects:block];
}
- (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];
}
- (void)removeObjectAtDucmentPathWithkey:(NSString *)key{
[[WMDocumentCache sharedCache].diskCache removeObjectForKey:key];
}
- (void)removeAllObjectsAtDucmentPath{
[[WMDocumentCache sharedCache].diskCache removeAllObjects];
}
@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
Copyright (c) 2016 wangyang <wangyang@wanmeizhensuo.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# GMCache
[![CI Status](http://img.shields.io/travis/wangyang/GMCache.svg?style=flat)](https://travis-ci.org/wangyang/GMCache)
[![Version](https://img.shields.io/cocoapods/v/GMCache.svg?style=flat)](http://cocoapods.org/pods/GMCache)
[![License](https://img.shields.io/cocoapods/l/GMCache.svg?style=flat)](http://cocoapods.org/pods/GMCache)
[![Platform](https://img.shields.io/cocoapods/p/GMCache.svg?style=flat)](http://cocoapods.org/pods/GMCache)
## Usage
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
## Installation
GMCache is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod "GMCache"
```
## Author
wangyang, wangyang@wanmeizhensuo.com
## License
GMCache is available under the MIT license. See the LICENSE file for more info.
#import <Foundation/Foundation.h>
@interface PodsDummy_GMCache : NSObject
@end
@implementation PodsDummy_GMCache
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import <UIKit/UIKit.h>
#import "WMCacheService.h"
FOUNDATION_EXPORT double GMCacheVersionNumber;
FOUNDATION_EXPORT const unsigned char GMCacheVersionString[];
framework module GMCache {
umbrella header "GMCache-umbrella.h"
export *
module * { export * }
}
CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/GMCache
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/TMCache"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
SKIP_INSTALL = YES
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
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