Commit 0db5e73 1 parent 88f11c7 commit 0db5e73 Copy full SHA for 0db5e73
File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import Foundation
3
3
/// A simple LRU key-value cache
4
4
class Cache < Key: Hashable , Value>
5
5
{
6
- class Wrapper
6
+ private class Wrapper
7
7
{
8
8
var accessed : Date
9
9
let object : Value
@@ -22,6 +22,9 @@ class Cache<Key: Hashable, Value>
22
22
23
23
private var contents : [ Key : Wrapper ] = [ : ]
24
24
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.
25
28
public var maxSize : Int
26
29
{
27
30
didSet
@@ -37,6 +40,8 @@ class Cache<Key: Hashable, Value>
37
40
self . maxSize = maxSize
38
41
}
39
42
43
+ /// This is the interface for accessing, adding and deleting entries.
44
+ /// Accessing an entry updates its timestamp.
40
45
subscript( key: Key ) -> Value ?
41
46
{
42
47
get
@@ -58,7 +63,7 @@ class Cache<Key: Hashable, Value>
58
63
}
59
64
}
60
65
61
- func purge( forAdditionalSpace space: Int )
66
+ private func purge( forAdditionalSpace space: Int )
62
67
{
63
68
while contents. count + space > maxSize {
64
69
if let oldest = contents. min ( by: { $0. value. accessed < $1. value. accessed } ) {
You can’t perform that action at this time.
0 commit comments