@@ -9,14 +9,32 @@ import (
9
9
10
10
// CacheEntry represents a single entry in the cache.
11
11
type CacheEntry interface {
12
+ // Key returns the key associated with the cache entry.
12
13
Key () string
14
+
15
+ // Value returns the value stored in the cache entry.
13
16
Value () any
17
+
18
+ // Age returns the age of the cache entry in seconds.
14
19
Age () float64
20
+
21
+ // Messages retrieves the number of messages processed by the entry.
15
22
Messages () uint64
23
+
24
+ // Bytes returns the size of bytes processed by the entry.
16
25
Bytes () uint64
26
+
27
+ // IsTooOld checks if the entry has exceeded its lifetime.
17
28
IsTooOld () bool
29
+
30
+ // IsValid checks if the entry is still valid.
18
31
IsValid () bool
32
+
33
+ // UpdateMeta updates the metadata of the cache entry
34
+ // with the number of bytes of plaintext to be encrypted.
19
35
UpdateMeta (b int )
36
+
37
+ // Invalidate marks the cache entry as invalid.
20
38
Invalidate ()
21
39
}
22
40
@@ -26,17 +44,34 @@ type CacheEntry interface {
26
44
// Custom cache implementations should implement this interface
27
45
// to be used with [CryptoMaterialsManager].
28
46
type Cache interface {
47
+ // PutEncryptionEntry adds an encryption material to the cache.
48
+ // It accepts a key, encryption material, n is len of bytes to be encrypted, and lifetime.
49
+ // The method returns a CacheEntry object containing the added entry.
29
50
PutEncryptionEntry (key string , em EncryptionMaterial , n int , lifetime time.Duration ) CacheEntry
51
+
52
+ // PutDecryptionEntry stores a decryption material in the cache with a specified key.
53
+ // The method returns the added or updated cache entry.
30
54
PutDecryptionEntry (key string , dm DecryptionMaterial , lifetime time.Duration ) CacheEntry
55
+
56
+ // GetEncryptionEntry retrieves an encryption entry from the cache using a specified key.
57
+ // It updates the metadata with the provided number of bytes.
58
+ // Returns the cache entry and a boolean indicating success.
31
59
GetEncryptionEntry (key string , n int ) (CacheEntry , bool )
60
+
61
+ // GetDecryptionEntry retrieves a decryption entry from the cache using a key.
62
+ // It returns the cache entry and a boolean indicating success.
32
63
GetDecryptionEntry (key string ) (CacheEntry , bool )
64
+
65
+ // DeleteEntry removes the cache entry associated with the specified key.
66
+ // It returns true if the entry was removed successfully.
33
67
DeleteEntry (key string ) bool
68
+
69
+ // Len returns the number of entries in the cache.
34
70
Len () int
35
71
}
36
72
37
73
// CacheHasher defines an interface to compute hashes for cache keys.
38
74
type CacheHasher interface {
39
-
40
75
// Update processes the input byte slice `p` to update the hash state.
41
76
Update (p []byte )
42
77
0 commit comments