-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemcacheFlag.swift
300 lines (254 loc) · 7.35 KB
/
MemcacheFlag.swift
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/// Flags for Meta Get, Set, Delete, and Arithmetic commands. Meta Debug and Meta No-Op don't support flags.
enum MemcacheFlag {
// MARK: Common flags
/// Interpret key as base64 encoded binary value.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**
/// - **Meta Delete**
/// - **Meta Arithmetic**
case b
/// Return item CAS token.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**: Return item's CAS token if successfully stored.
/// - **Meta Arithmetic**: Return item's CAS token if successfully stored.
case c
/// Return key as a token.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**
/// - **Meta Delete**
case k
/// Opaque value, consumes a token and copies back with response.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**
/// - **Meta Delete**
case O(OpaqueToken)
/// Use noreply semantics for return codes.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**
/// - **Meta Delete**
/// - **Meta Arithmetic**
case q
/// Return item value in \<data block\>.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Arithmetic**: Return new value.
case v
/// Return item TTL remaining in seconds (-1 for unlimited).
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Arithmetic**
case t
/// Update remaining TTL.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Set**
/// - **Meta Delete**: Updates TTL, only when paired with the `.I` flag.
/// - **Meta Arithmetic**: Update TTL on success.
case T(TTLToken)
/// Compare CAS value.
///
/// Available for the following commands:
/// - **Meta Set**: Compare CAS value when storing item.
/// - **Meta Delete**
/// - **Meta Arithmetic**
case C(NumericToken<UInt64>)
/// Invalidate: set to invalid if supplied CAS is older than item's CAS.
///
/// Available for the following commands:
/// - **Meta Set**
/// - **Meta Delete**
case I
/// Vivify on miss, takes TTL as a argument.
///
/// Available for the following commands:
/// - **Meta Get**
/// - **Meta Arithmetic**: Auto-create item on miss with supplied TTL.
case N(TTLToken)
/// Mode switch.
///
/// Available for the following commands:
/// - **Meta Set**: Mode switch to change behavior to add, replace, append, prepend.
/// - **Meta Arithmetic**: Mode switch to change between incr and decr modes.
case M(ModeToken)
// MARK: 'Get'-only flags
/// Return client flags token.
///
/// Available for the following commands:
/// - **Meta Get**
case f
/// Return whether item has been hit before as a 0 or 1.
///
/// Available for the following commands:
/// - **Meta Get**
case h
/// Return time since item was last accessed in seconds.
///
/// Available for the following commands:
/// - **Meta Get**
case l
/// Return item size token.
///
/// Available for the following commands:
/// - **Meta Get**
case s
/// Don't bump the item in the LRU.
///
/// Available for the following commands:
/// - **Meta Get**
case u
/// If token is less than remaining TTL win for recache.
///
/// Available for the following commands:
/// - **Meta Get**
case R(TTLToken)
/// Client has "won" the recache flag.
///
/// Available for the following commands:
/// - **Meta Get**
case W
/// Item is stale.
///
/// Available for the following commands:
/// - **Meta Get**
case X
/// Item has already sent a winning flag.
///
/// Available for the following commands:
/// - **Meta Get**
case Z
// MARK: 'Set'-only flags
/// Set client flags to token.
///
/// Available for the following commands:
/// - **Meta Set**
case F(NumericToken<UInt32>) // TODO: Docs say '32 bit unsigned numeric'
// MARK: 'Delete'-only flags
// No 'Delete'-only flags
// MARK: 'Arithmetic'-only flags
/// Initial value to use if auto created after miss (default 0).
///
/// Available for the following commands:
/// - **Meta Arithmetic**
case J(NumericToken<UInt64>)
/// Delta to apply (default 1).
///
/// Available for the following commands:
/// - **Meta Arithmetic**
case D(NumericToken<UInt64>) // TODO: Docs say 'unsigned decimal number'
// MARK: Ignored tokens
/// This flag is completely ignored by the memcached daemon. It can be used as a hint or path specification to a proxy or
/// router inbetween a client and the memcached daemon.
case P(StringToken)
/// This flag is completely ignored by the memcached daemon. It can be used as a hint or path specification to a proxy or
/// router inbetween a client and the memcached daemon.
case L(StringToken)
}
extension MemcacheFlag: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .b:
return ".b"
case .c:
return ".c"
case .k:
return ".k"
case let .O(token):
return ".O(\(token))"
case .q:
return ".q"
case .v:
return ".v"
case .t:
return ".t"
case let .T(token):
return ".T(\(token))"
case let .C(token):
return ".C(\(token))"
case .I:
return ".I"
case let .N(token):
return ".N(\(token))"
case let .M(token):
return ".M(\(token))"
case .f:
return ".f"
case .h:
return ".h"
case .l:
return ".l"
case .s:
return ".s"
case .u:
return ".u"
case let .R(token):
return ".R(\(token))"
case .W:
return ".W"
case .X:
return ".X"
case .Z:
return ".Z"
case let .F(token):
return ".F(\(token))"
case let .J(token):
return ".J(\(token))"
case let .D(token):
return ".D(\(token))"
case let .P(token):
return ".P(\(token))"
case let .L(token):
return ".L(\(token))"
}
}
}
// MARK: -
extension MemcacheFlag {
enum Code: Character {
// MARK: Common flags
case b = "b"
case c = "c"
case k = "k"
case O = "O"
case q = "q"
case v = "v"
case t = "t"
case T = "T"
case C = "C"
case I = "I"
case N = "N"
case M = "M"
// MARK: 'Get'-only flags
case f = "f"
case h = "h"
case l = "l"
case s = "s"
case u = "u"
case R = "R"
case W = "W"
case X = "X"
case Z = "Z"
// MARK: 'Set'-only flags
case F = "F"
// MARK: 'Delete'-only flags
// No 'Delete'-only flags
// MARK: 'Arithmetic'-only flags
case J = "J"
case D = "D"
// MARK: Ignored flags
case P = "P"
case L = "L"
}
}