datastore

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

persist/datastore

Google Cloud Datastore persistence with native TTL support.

Features

  • Scales automatically, native TTL support
  • JSON encoding with base64 for binary safety
  • Streaming loads for warmup
  • Works across Cloud Run instances

Usage

import (
    "github.com/codeGROOVE-dev/sfcache"
    "github.com/codeGROOVE-dev/sfcache/persist/datastore"
)

// cacheID becomes the Datastore database name
p, _ := datastore.New[string, User](ctx, "myapp")

// Optional: clean up stale entries on startup
p.Cleanup(ctx, 24*time.Hour)

cache, _ := sfcache.New[string, User](ctx,
    sfcache.WithPersistence(p))
gcloud firestore fields ttls update expiry \
  --collection-group=CacheEntry \
  --enable-ttl \
  --database=myapp

One-time setup per database. Datastore deletes expired entries within 24 hours.

Fallback Pattern

p, err := datastore.New[string, User](ctx, "myapp")
if err != nil {
    p, _ = localfs.New[string, User]("myapp", "")
}

Key Constraints

  • Maximum key length: 1500 characters (Datastore limit)

Documentation

Overview

Package datastore provides Google Cloud Datastore persistence for sfcache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[K comparable, V any](ctx context.Context, cacheID string) (persist.Store[K, V], error)

New creates a new Datastore-based persistence layer. The cacheID is used as the Datastore database name. An empty projectID will be auto-detected from the environment.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL