BDPKVManager.h
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// BDPKVManager.h
// BDPKV
//
// Created by performance for gaobingnan on 2021/3/1.
//
#import <Foundation/Foundation.h>
#import "BDPMemoryKV.h"
#import "BDPDiskKV.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_OPTIONS(NSUInteger, BDPKVMode) {
BDPKVModeMemory = (0x1 << 1), // 仅内存模式
BDPKVModeDisk = (0x1 << 2), // 磁盘模式,内部同时支持内存缓存
BDPKVModeMemoryAndDisk = (0x1 << 3), // 磁盘模式+内存模式(适用于内存和磁盘存储的内容相互独立)
};
@interface BDPKVManager : NSObject
/// name of kv object
@property (nonatomic, copy, readonly) NSString *name;
/// only memory kv
@property (nonatomic, strong, readonly) BDPMemoryKV *memoryKV;
/// disk kv, include memory kv
@property (nonatomic, strong, readonly) BDPDiskKV *diskKV;
#pragma mark - create Methods
/**
Create a new instance with the specified name.
⚠️Multiple instances with the same name will make the kv unstable.
The default mode is BDPKVModeMemory.
@param name The name of the kv.
@result A new kv object, or nil if an error occurs.
*/
- (nullable instancetype)initWithName:(NSString *)name;
/**
Create a new instance with the specified name.
⚠️Multiple instances with the same name will make the kv unstable.
The default sandbox path is Documents/bdpkv/disk/.
@param name The name of the kv.
@param mode The mode of the kv.
@result A new kv object, or nil if an error occurs.
*/
- (nullable instancetype)initWithName:(NSString *)name mode:(BDPKVMode)mode;
/**
Create a new instance with the specified path.
⚠️Multiple instances with the same name will make the kv unstable.
The default value is BDPKVModeMemory.
@param path Full path of a directory in which the kv will write data.
Once initialized you should not read and write to this directory.
@result A new kv object, or nil if an error occurs.
*/
- (nullable instancetype)initWithPath:(NSString *)path;
/**
Create a new instance with the specified path.
Multiple instances with the same name will make the kv unstable.
@param path Full path of a directory in which the kv will write data.
Once initialized you should not read and write to this directory.
@param mode The mode of the kv.
@result A new kv object, or nil if an error occurs.
*/
- (nullable instancetype)initWithPath:(NSString *)path mode:(BDPKVMode)mode;
/**
find instance with the specified name.
Multiple instances with the same name will make the kv unstable.
@param name The name of the kv.
@result A created kv object, or nil if not find.
*/
+ (nullable instancetype)findKVWithName:(NSString *)name;
/**
find instance with the specified name.
Multiple instances with the same name will make the kv unstable.
@param path The path of the kv.
@result A created kv object, or nil if not find.
*/
+ (nullable instancetype)findKVWithPath:(NSString *)path;
@end
NS_ASSUME_NONNULL_END