BUPersistence.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // BUPersistence.h
  3. // BUPersistence
  4. //
  5. // Created by Chen Hong on 2017/1/10.
  6. // Copyright © 2017年 Chen Hong. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. typedef NS_ENUM(NSUInteger, BUPersistentType) {
  11. BUPersistentTypePlist,
  12. BUPersistentTypeMMAP,
  13. BUPersistentTypeCustom,
  14. };
  15. @interface BUPersistenceOption : NSObject
  16. @property (nonatomic, assign) BUPersistentType type;
  17. @property (nonatomic, assign) BOOL shouldRemoveAllObjectsOnMemoryWarning;
  18. @property (nonatomic, assign) BOOL shouldRemoveAllObjectsWhenEnteringBackground;
  19. @property (nonatomic, assign) BOOL supportNSCoding;
  20. /// 4000 是否需要LRU删除缓存
  21. @property (nonatomic, assign) BOOL supportLRU;
  22. /// 4400 缓存个数,默认为最大整数不限制
  23. @property (nonatomic, assign) NSUInteger capacityCount;
  24. /// 4400 缓存大小,默认为10M,暂时不支持
  25. @property (nonatomic, assign) NSUInteger capacitySize;
  26. @end
  27. @protocol BUPersistenceProtocol <NSObject>
  28. - (NSArray *)allObjects;
  29. - (void)allObjectsWithSafeBlock:(void(^)(NSArray *))block;
  30. - (nullable id)objectForKey:(nullable NSString *)key;
  31. - (nullable NSArray *)objectsForKeys:(NSArray *)keys;
  32. - (void)updateObjectsForKeys:(NSArray *)keys WithBlock:(NSDictionary * (^)(NSArray *objects))block;
  33. - (BOOL)setObject:(nullable id<NSCoding, NSObject>)object forKey:(nullable NSString *)key;
  34. - (BOOL)hasObjectForKey:(nullable NSString *)key;
  35. - (BOOL)removeAll;
  36. - (BOOL)removeObjectsForKeys:(NSArray<NSString *> *)keys;
  37. - (BOOL)save;
  38. @optional
  39. - (void)onMemoryWarning;
  40. @end
  41. @interface BUPersistence : NSObject <BUPersistenceProtocol>
  42. + (nullable instancetype)persistenceWithName:(NSString *)name;
  43. /// 公共的BUPersistence 实例对象
  44. /// 当不需要特定的设置name时,可以使用commonPersistence
  45. /// @Warning , 当使用commonPersistence时, key值的设置请注意唯一性,防止key值覆盖的问题发生
  46. + (nullable instancetype)commonPersistence;
  47. + (nullable instancetype)persistenceWithName:(NSString *)name option:(BUPersistenceOption *)option;
  48. + (NSString *)cacheDirectory;
  49. #pragma mark - Publick
  50. + (void)setSDKVersion:(NSString *)sdkVersion;
  51. + (NSString *)sdkVersion;
  52. @end
  53. NS_ASSUME_NONNULL_END