@@ -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