ItemCacheTable
public typealias ItemCacheCollectionId = Int8
class
ItemCacheEntryId
1
2
public let collectionId: ItemCacheCollectionId
public let key: ValueBoxKey
enum
ItemCacheSection
1
2
3
case items = 0
case accessIndexToItemId = 1
case itemIdToAccessIndex = 2
class
ItemCacheTable:
Table
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
static func tableSpec(_ id: Int32) -> ValueBoxTable {
return ValueBoxTable(id: id, keyType: .binary, compactValuesOnCreation: false)
}
private func itemKey(id: ItemCacheEntryId) -> ValueBoxKey {
let key = ValueBoxKey(length: 1 + 1 + id.key.length)
// ItemCacheSection + id.collectionId + id.key
key.setInt8(0, value: ItemCacheSection.items.rawValue)
key.setInt8(1, value: id.collectionId)
memcpy(key.memory.advanced(by: 2), id.key.memory, id.key.length)
return key
}
private func lowerBound(collectionId: ItemCacheCollectionId) -> ValueBoxKey {
let key = ValueBoxKey(length: 1 + 1)
// ItemCacheSection + collectionId
key.setInt8(0, value: ItemCacheSection.items.rawValue)
key.setInt8(1, value: collectionId)
return key
}
private func upperBound(collectionId: ItemCacheCollectionId) -> ValueBoxKey {
return self.lowerBound(collectionId: collectionId).successor
}
private func itemIdToAccessIndexKey(id: ItemCacheEntryId) -> ValueBoxKey {
let key = ValueBoxKey(length: 1 + 1 + id.key.length)
// ItemCacheSection + id.collectionId + id.key
key.setInt8(0, value: ItemCacheSection.accessIndexToItemId.rawValue)
key.setInt8(1, value: id.collectionId)
memcpy(key.memory.advanced(by: 2), id.key.memory, id.key.length)
return key
}
private func accessIndexToItemId(collectionId: ItemCacheCollectionId, index: Int32) -> ValueBoxKey {
let key = ValueBoxKey(length: 1 + 1 + 4)
// ItemCacheSection + id.collectionId + index
key.setInt8(0, value: ItemCacheSection.accessIndexToItemId.rawValue)
key.setInt8(1, value: collectionId)
key.setInt32(2, value: index)
return key
}