didcache

package
v0.0.0-...-e6a591c Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DIDMaxLen = 2 * 1024

Variables

View Source
var (
	ErrNoCache      = errors.New("caching is disabled")
	ErrDIDTooLong   = errors.New("DID is too long (2048 chars max)")
	ErrFileTooBig   = errors.New("cached file is too large")
	ErrCacheExpired = errors.New("cached file is too old")
)

Functions

func NewFileCache

func NewFileCache(d identity.Directory, cleaner CacheCleaner, dir string) *cacheDirectory

func Purge

func Purge(ctx context.Context, db *sql.DB) error

Types

type CacheCleaner

type CacheCleaner interface {
	Stale(stat fs.FileInfo) bool
}

type CacheConfig

type CacheConfig struct{}

type DIDCache

type DIDCache struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB, staleTTL, maxTTL time.Duration) *DIDCache

func NewDIDCache

func NewDIDCache(dbLocation string, staleTTL, maxTTL time.Duration) (*DIDCache, error)

func NewDIDCacheFromDB

func NewDIDCacheFromDB(db *sql.DB, staleTTL, maxTTL time.Duration) (*DIDCache, error)

func (*DIDCache) CacheDoc

func (cache *DIDCache) CacheDoc(
	ctx context.Context,
	did string,
	doc *did.Document,
	prevResult *Result,
) error

func (*DIDCache) CachedDoc

func (cache *DIDCache) CachedDoc(ctx context.Context, didstr string) (*Result, error)

func (*DIDCache) Clear

func (cache *DIDCache) Clear(ctx context.Context) error

func (*DIDCache) ClearEntry

func (cache *DIDCache) ClearEntry(ctx context.Context, did string) error

func (*DIDCache) ClearHandle

func (cache *DIDCache) ClearHandle(ctx context.Context, handle string) error

func (*DIDCache) Close

func (cache *DIDCache) Close() error

func (*DIDCache) GetDID

func (cache *DIDCache) GetDID(ctx context.Context, handle string) (*Result, error)

func (*DIDCache) GetIdentity

func (cache *DIDCache) GetIdentity(ctx context.Context, did string) (*IdentityResult, error)

func (*DIDCache) InitializeSchema

func (cache *DIDCache) InitializeSchema() error

func (*DIDCache) SetLogger

func (cache *DIDCache) SetLogger(l *slog.Logger)

func (*DIDCache) StoreDID

func (cache *DIDCache) StoreDID(ctx context.Context, handle, did string) error

func (*DIDCache) StoreIdentity

func (cache *DIDCache) StoreIdentity(ctx context.Context, did string, ident *identity.Identity) error

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

func NewDirectory

func NewDirectory(
	dir identity.Directory,
	resolver did.Resolver,
	handles atp.HandleResolver,
	cache *DIDCache,
) *Directory

func (*Directory) Lookup

func (*Directory) LookupDID

func (d *Directory) LookupDID(ctx context.Context, did syntax.DID) (*identity.Identity, error)

func (*Directory) LookupHandle

func (d *Directory) LookupHandle(ctx context.Context, h syntax.Handle) (*identity.Identity, error)

func (*Directory) Purge

func (d *Directory) Purge(ctx context.Context, i syntax.AtIdentifier) error

Flushes any cache of the indicated identifier. If directory is not using caching, can ignore this.

type HandleResolver

type HandleResolver struct {
	// contains filtered or unexported fields
}

func NewHandleResolver

func NewHandleResolver(resolver atp.HandleResolver, cache *DIDCache) *HandleResolver

func (*HandleResolver) ResolveHandle

func (hr *HandleResolver) ResolveHandle(ctx context.Context, handle string) (syntax.DID, error)

type IdentityResult

type IdentityResult struct {
	Ident     identity.Identity
	UpdatedAt time.Time
	DID       string
	Stale     bool
	Expired   bool
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

func NewDIDResolver

func NewDIDResolver(resolver did.Resolver, cache *DIDCache) *Resolver

func (*Resolver) FlushCacheFor

func (r *Resolver) FlushCacheFor(didstr string)

func (*Resolver) GetDocument

func (r *Resolver) GetDocument(ctx context.Context, didstr string) (*did.Document, error)

type Result

type Result struct {
	Doc       did.Document
	UpdatedAt time.Time
	DID       string
	// If stale is true but expired is false, the entry is still usable but
	// should be refreshed soon.
	Stale bool
	// If expired is true, the entry is considered invalid and should not be
	// used without refreshing or replacing it.
	Expired bool
}

Jump to

Keyboard shortcuts

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