This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
forked from Synthetic/SYCache
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSAMCache.h
executable file
·174 lines (117 loc) · 3.96 KB
/
SAMCache.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// SAMCache.h
// SAMCache
//
// Created by Sam Soffes on 10/31/11.
// Copyright © 2011-2015 Sam Soffes. All rights reserved.
//
@import Foundation;
@interface SAMCache : NSObject
///-----------------
/// @name Properties
///-----------------
/**
The name of the cache.
*/
@property (nonatomic, readonly) NSString *name;
/**
The directory of the on-disk cache.
*/
@property (nonatomic, readonly) NSString *directory;
///-------------------------------
/// @name Getting the Shared Cache
///-------------------------------
/**
Shared cache suitable for all of your caching needs.
@return A shared cache.
*/
+ (SAMCache *)sharedCache;
///-------------------
/// @name Initializing
///-------------------
/**
Initialize a separate cache from the shared cache. It may be handy to make a separate cache from the shared cache in
case you need to call `removeAllObjects` or change the location.
The on-disk cache will be stored at `~/Library/Caches/com.samsoffes.samcache/NAME/`.
@param name A string to identify the cache.
@return A new cache.
*/
- (instancetype)initWithName:(NSString *)name;
/**
Initialize a separate cache from the shared cache. It may be handy to make a separate cache from the shared cache in
case you need to call `removeAllObjects` or change the location.
@param name A string to identify the cache.
@param directory A path to the on-disk cache directory. It will be created if it does not exist. If you pass `nil` it
will default to `~/Library/Caches/com.samsoffes.samcache/NAME/`.
@return A new cache.
*/
- (instancetype)initWithName:(NSString *)name directory:(NSString *)directory;
///-----------------------------
/// @name Getting a Cached Value
///-----------------------------
/**
Synchronously get an object from the cache.
@param key The key of the object.
@return The object for the given key or `nil` if it does not exist.
*/
- (id)objectForKey:(NSString *)key;
/**
Asynchronously get an object from the cache.
@param key The key of the object.
@param block A block called on an arbitrary queue with the requested object or `nil` if it does not exist.
*/
- (void)objectForKey:(NSString *)key usingBlock:(void (^)(id <NSCopying> object))block;
/**
Synchronously check if an object exists in the cache without retriving it.
@param key The key of the object.
@return A boolean specifying if the object exists or not.
*/
- (BOOL)objectExistsForKey:(NSString *)key;
///----------------------------------------
/// @name Adding and Removing Cached Values
///----------------------------------------
/**
Synchronously set an object in the cache for a given key.
@param object The object to store in the cache.
@param key The key of the object.
*/
- (void)setObject:(id <NSCoding>)object forKey:(NSString *)key;
/**
Remove an object from the cache.
@param key The key of the object.
*/
- (void)removeObjectForKey:(NSString *)key;
/**
Remove all objects from the cache.
*/
- (void)removeAllObjects;
///-------------------------------
/// @name Accessing the Disk Cache
///-------------------------------
/**
Returns the path to the object on disk associated with a given key.
@param key An object identifying the value.
@return Path to object on disk or `nil` if no object exists for the given `key`.
*/
- (NSString *)pathForKey:(NSString *)key;
///-------------------
/// @name Subscripting
///-------------------
/**
Synchronously get an object from the cache.
@param key The key of the object.
@return The object for the given key or `nil` if it does not exist.
This method behaves the same as `objectForKey:`.
*/
- (id)objectForKeyedSubscript:(NSString *)key;
/**
Synchronously set an object in the cache for a given key.
@param object The object to store in the cache.
@param key The key of the object.
This method behaves the same as `setObject:forKey:`.
*/
- (void)setObject:(id <NSCoding>)object forKeyedSubscript:(NSString *)key;
@end
#if TARGET_OS_IPHONE
#import <SAMCache/SAMCache+Image.h>
#endif