Skip to content

Commit 6e48ca9

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
consistent terminology
1 parent 4bd7465 commit 6e48ca9

File tree

9 files changed

+298
-298
lines changed

9 files changed

+298
-298
lines changed

persistent_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestPersistentCache_Basic(t *testing.T) {
206206
// Verify it's in persistence
207207
val, _, found, err := store.Get(ctx, "key1")
208208
if err != nil {
209-
t.Fatalf("store.Load: %v", err)
209+
t.Fatalf("store.Get: %v", err)
210210
}
211211
if !found {
212212
t.Error("key1 should be persisted")
@@ -222,7 +222,7 @@ func TestPersistentCache_Basic(t *testing.T) {
222222

223223
_, _, found, err = store.Get(ctx, "key1")
224224
if err != nil {
225-
t.Fatalf("store.Load after delete: %v", err)
225+
t.Fatalf("store.Get after delete: %v", err)
226226
}
227227
if found {
228228
t.Error("key1 should be deleted from persistence")
@@ -336,7 +336,7 @@ func TestPersistentCache_SetAsync(t *testing.T) {
336336
// Should also be persisted
337337
val, _, found, err = store.Get(ctx, "key1")
338338
if err != nil {
339-
t.Fatalf("store.Load: %v", err)
339+
t.Fatalf("store.Get: %v", err)
340340
}
341341
if !found || val != 42 {
342342
t.Error("key1 should be persisted after SetAsync")
@@ -733,7 +733,7 @@ func TestPersistentCache_GetOrSet(t *testing.T) {
733733
// Value should be persisted
734734
persistedVal, _, found, err := store.Get(ctx, "key1")
735735
if err != nil {
736-
t.Fatalf("store.Load: %v", err)
736+
t.Fatalf("store.Get: %v", err)
737737
}
738738
if !found || persistedVal != 42 {
739739
t.Error("key1 should be persisted")
@@ -907,14 +907,14 @@ func TestPersistentCache_SetAsync_VariadicTTL(t *testing.T) {
907907
// Both should be persisted
908908
_, _, found, err = store.Get(ctx, "async-default")
909909
if err != nil {
910-
t.Fatalf("store.Load: %v", err)
910+
t.Fatalf("store.Get: %v", err)
911911
}
912912
if !found {
913913
t.Error("async-default should be persisted")
914914
}
915915
_, _, found, err = store.Get(ctx, "async-explicit")
916916
if err != nil {
917-
t.Fatalf("store.Load: %v", err)
917+
t.Fatalf("store.Get: %v", err)
918918
}
919919
if !found {
920920
t.Error("async-explicit should be persisted")

pkg/persist/cloudrun/cloudrun_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ func TestNew_BasicOperations(t *testing.T) {
8888

8989
err = p.Set(ctx, key, value, time.Time{})
9090
if err != nil {
91-
t.Fatalf("Store() failed: %v", err)
91+
t.Fatalf("Set() failed: %v", err)
9292
}
9393

9494
got, _, found, err := p.Get(ctx, key)
9595
if err != nil {
96-
t.Fatalf("Load() failed: %v", err)
96+
t.Fatalf("Get() failed: %v", err)
9797
}
9898
if !found {
99-
t.Fatal("Load() should find stored value")
99+
t.Fatal("Get() should find stored value")
100100
}
101101
if got != value {
102-
t.Errorf("Load() = %v, want %v", got, value)
102+
t.Errorf("Get() = %v, want %v", got, value)
103103
}
104104
}
105105

@@ -242,7 +242,7 @@ func TestNew_CloudRunFallbackWithDelete(t *testing.T) {
242242

243243
// Store and delete
244244
if err := p.Set(ctx, "key1", 100, time.Time{}); err != nil {
245-
t.Fatalf("Store() failed: %v", err)
245+
t.Fatalf("Set() failed: %v", err)
246246
}
247247

248248
if err := p.Delete(ctx, "key1"); err != nil {
@@ -252,7 +252,7 @@ func TestNew_CloudRunFallbackWithDelete(t *testing.T) {
252252
// Verify deleted
253253
_, _, found, err := p.Get(ctx, "key1")
254254
if err != nil {
255-
t.Fatalf("Load() failed: %v", err)
255+
t.Fatalf("Get() failed: %v", err)
256256
}
257257
if found {
258258
t.Error("key should be deleted")

pkg/persist/datastore/datastore.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const (
1818
maxDatastoreKeyLen = 1500 // Datastore has stricter key length limits
1919
)
2020

21-
// datastorePersist implements PersistenceLayer using Google Cloud Datastore.
22-
type persister[K comparable, V any] struct {
21+
// store implements Store using Google Cloud Datastore.
22+
type store[K comparable, V any] struct {
2323
client *ds.Client
2424
kind string
2525
}
2626

2727
// ValidateKey checks if a key is valid for Datastore persistence.
2828
// Datastore has stricter key length limits than files.
29-
func (*persister[K, V]) ValidateKey(key K) error {
29+
func (*store[K, V]) ValidateKey(key K) error {
3030
s := fmt.Sprintf("%v", key)
3131
if len(s) > maxDatastoreKeyLen {
3232
return fmt.Errorf("key too long: %d bytes (max %d for datastore)", len(s), maxDatastoreKeyLen)
@@ -38,9 +38,9 @@ func (*persister[K, V]) ValidateKey(key K) error {
3838
}
3939

4040
// Location returns the Datastore key path for a given cache key.
41-
// Implements the PersistenceLayer interface Location() method.
41+
// Implements the Store interface Location() method.
4242
// Format: "kind/key" (e.g., "CacheEntry/mykey").
43-
func (p *persister[K, V]) Location(key K) string {
43+
func (p *store[K, V]) Location(key K) string {
4444
return fmt.Sprintf("%s/%v", p.kind, key)
4545
}
4646

@@ -66,22 +66,22 @@ func New[K comparable, V any](ctx context.Context, cacheID string) (persist.Stor
6666
// Verify connectivity (assert readiness)
6767
// Note: ds9 doesn't expose Ping, but client creation validates connectivity
6868

69-
return &persister[K, V]{
69+
return &store[K, V]{
7070
client: client,
7171
kind: datastoreKind,
7272
}, nil
7373
}
7474

7575
// makeKey creates a Datastore key from a cache key.
7676
// We use the string representation directly as the key name.
77-
func (p *persister[K, V]) makeKey(key K) *ds.Key {
77+
func (p *store[K, V]) makeKey(key K) *ds.Key {
7878
return ds.NameKey(p.kind, fmt.Sprintf("%v", key), nil)
7979
}
8080

8181
// Get retrieves a value from Datastore.
8282
//
8383
//nolint:revive // function-result-limit - required by persist.Store interface
84-
func (p *persister[K, V]) Get(ctx context.Context, key K) (value V, expiry time.Time, found bool, err error) {
84+
func (p *store[K, V]) Get(ctx context.Context, key K) (value V, expiry time.Time, found bool, err error) {
8585
var zero V
8686
dsKey := p.makeKey(key)
8787

@@ -114,7 +114,7 @@ func (p *persister[K, V]) Get(ctx context.Context, key K) (value V, expiry time.
114114
}
115115

116116
// Set saves a value to Datastore.
117-
func (p *persister[K, V]) Set(ctx context.Context, key K, value V, expiry time.Time) error {
117+
func (p *store[K, V]) Set(ctx context.Context, key K, value V, expiry time.Time) error {
118118
dsKey := p.makeKey(key)
119119

120120
// Encode value as JSON then base64
@@ -138,7 +138,7 @@ func (p *persister[K, V]) Set(ctx context.Context, key K, value V, expiry time.T
138138
}
139139

140140
// Delete removes a value from Datastore.
141-
func (p *persister[K, V]) Delete(ctx context.Context, key K) error {
141+
func (p *store[K, V]) Delete(ctx context.Context, key K) error {
142142
dsKey := p.makeKey(key)
143143

144144
if err := p.client.Delete(ctx, dsKey); err != nil {
@@ -149,7 +149,7 @@ func (p *persister[K, V]) Delete(ctx context.Context, key K) error {
149149
}
150150

151151
// LoadRecent streams entries from Datastore, returning up to 'limit' most recently updated entries.
152-
func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-chan persist.Entry[K, V], errs <-chan error) {
152+
func (p *store[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-chan persist.Entry[K, V], errs <-chan error) {
153153
entryCh := make(chan persist.Entry[K, V], 100)
154154
errCh := make(chan error, 1)
155155

@@ -230,7 +230,7 @@ func (p *persister[K, V]) LoadRecent(ctx context.Context, limit int) (entries <-
230230
// Cleanup removes expired entries from Datastore.
231231
// maxAge specifies how old entries must be (based on expiry field) before deletion.
232232
// If native Datastore TTL is properly configured, this will find no entries.
233-
func (p *persister[K, V]) Cleanup(ctx context.Context, maxAge time.Duration) (int, error) {
233+
func (p *store[K, V]) Cleanup(ctx context.Context, maxAge time.Duration) (int, error) {
234234
cutoff := time.Now().Add(-maxAge)
235235

236236
// Query for entries with expiry before cutoff
@@ -260,7 +260,7 @@ func (p *persister[K, V]) Cleanup(ctx context.Context, maxAge time.Duration) (in
260260

261261
// Flush removes all entries from Datastore.
262262
// Returns the number of entries removed and any error.
263-
func (p *persister[K, V]) Flush(ctx context.Context) (int, error) {
263+
func (p *store[K, V]) Flush(ctx context.Context) (int, error) {
264264
// Query for all keys
265265
query := ds.NewQuery(p.kind).KeysOnly()
266266

@@ -283,7 +283,7 @@ func (p *persister[K, V]) Flush(ctx context.Context) (int, error) {
283283
}
284284

285285
// Len returns the number of entries in Datastore.
286-
func (p *persister[K, V]) Len(ctx context.Context) (int, error) {
286+
func (p *store[K, V]) Len(ctx context.Context) (int, error) {
287287
query := ds.NewQuery(p.kind).KeysOnly()
288288
keys, err := p.client.GetAll(ctx, query, nil)
289289
if err != nil {
@@ -293,6 +293,6 @@ func (p *persister[K, V]) Len(ctx context.Context) (int, error) {
293293
}
294294

295295
// Close releases Datastore client resources.
296-
func (p *persister[K, V]) Close() error {
296+
func (p *store[K, V]) Close() error {
297297
return p.client.Close()
298298
}

0 commit comments

Comments
 (0)