Skip to content

Commit 0db5e73

Browse files
committed
Comments for Cache
1 parent 88f11c7 commit 0db5e73

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Xit/Utils/Cache.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
/// A simple LRU key-value cache
44
class Cache<Key: Hashable, Value>
55
{
6-
class Wrapper
6+
private class Wrapper
77
{
88
var accessed: Date
99
let object: Value
@@ -22,6 +22,9 @@ class Cache<Key: Hashable, Value>
2222

2323
private var contents: [Key: Wrapper] = [:]
2424
private let mutex = Mutex()
25+
26+
/// The maximum number of entries. If the maximum is exceeded, then entries
27+
/// are purged starting with the least recently accessed.
2528
public var maxSize: Int
2629
{
2730
didSet
@@ -37,6 +40,8 @@ class Cache<Key: Hashable, Value>
3740
self.maxSize = maxSize
3841
}
3942

43+
/// This is the interface for accessing, adding and deleting entries.
44+
/// Accessing an entry updates its timestamp.
4045
subscript(key: Key) -> Value?
4146
{
4247
get
@@ -58,7 +63,7 @@ class Cache<Key: Hashable, Value>
5863
}
5964
}
6065

61-
func purge(forAdditionalSpace space: Int)
66+
private func purge(forAdditionalSpace space: Int)
6267
{
6368
while contents.count + space > maxSize {
6469
if let oldest = contents.min(by: { $0.value.accessed < $1.value.accessed }) {

0 commit comments

Comments
 (0)