Skip to content

Commit 1473723

Browse files
committed
docs(cache): improve CacheEntry and Cache interface documentation
1 parent cb3cfbc commit 1473723

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

pkg/materials/cache/memory_cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (m *MemoryCache) PutDecryptionEntry(key string, dm model.DecryptionMaterial
7171
return m.storeCacheEntry(key, entry)
7272
}
7373

74-
// GetEncryptionEntry retrieves a encryption entry from the cache using a specified key.
74+
// GetEncryptionEntry retrieves an encryption entry from the cache using a specified key.
7575
// It updates the metadata with the provided number of bytes.
7676
// Returns the cache entry and a boolean indicating success.
7777
func (m *MemoryCache) GetEncryptionEntry(key string, n int) (model.CacheEntry, bool) {

pkg/model/cache.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,32 @@ import (
99

1010
// CacheEntry represents a single entry in the cache.
1111
type CacheEntry interface {
12+
// Key returns the key associated with the cache entry.
1213
Key() string
14+
15+
// Value returns the value stored in the cache entry.
1316
Value() any
17+
18+
// Age returns the age of the cache entry in seconds.
1419
Age() float64
20+
21+
// Messages retrieves the number of messages processed by the entry.
1522
Messages() uint64
23+
24+
// Bytes returns the size of bytes processed by the entry.
1625
Bytes() uint64
26+
27+
// IsTooOld checks if the entry has exceeded its lifetime.
1728
IsTooOld() bool
29+
30+
// IsValid checks if the entry is still valid.
1831
IsValid() bool
32+
33+
// UpdateMeta updates the metadata of the cache entry
34+
// with the number of bytes of plaintext to be encrypted.
1935
UpdateMeta(b int)
36+
37+
// Invalidate marks the cache entry as invalid.
2038
Invalidate()
2139
}
2240

@@ -26,17 +44,34 @@ type CacheEntry interface {
2644
// Custom cache implementations should implement this interface
2745
// to be used with [CryptoMaterialsManager].
2846
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.
2950
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.
3054
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.
3159
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.
3263
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.
3367
DeleteEntry(key string) bool
68+
69+
// Len returns the number of entries in the cache.
3470
Len() int
3571
}
3672

3773
// CacheHasher defines an interface to compute hashes for cache keys.
3874
type CacheHasher interface {
39-
4075
// Update processes the input byte slice `p` to update the hash state.
4176
Update(p []byte)
4277

0 commit comments

Comments
 (0)