caches

package
v1.44.9 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCouldNotResolveCacheCluster = errRange.New(
		"Invalid Cache Keyspace Construction",
		`Could not resolve the cache cluster: must refer to a package level variable.`,
	)

	ErrDuplicateCacheCluster = errRange.New(
		"Duplicate Cache Cluster",
		"Cache clusters must have unique names.",

		errors.PrependDetails("I you wish to reuse the same cluster, export the original cache.Cluster object and reuse it here."),
	)

	ErrKeyspaceNotInService = errRange.New(
		"Invalid Cache Keyspace",
		"Cache keyspaces must be defined within a service.",
	)

	ErrKeyspaceUsedInOtherService = errRange.New(
		"Invalid Cache Keyspace Usage",
		"Cache keyspaces must be used within the same service they are defined in.",
	)
)
View Source
var ClusterParser = &resourceparser.Parser{
	Name: "Cache Cluster",

	InterestingImports: []paths.Pkg{"encore.dev/storage/cache"},
	Run: func(p *resourceparser.Pass) {
		name := pkginfo.QualifiedName{PkgPath: "encore.dev/storage/cache", Name: "NewCluster"}

		spec := &parseutil.ReferenceSpec{
			MinTypeArgs: 0,
			MaxTypeArgs: 0,
			Parse:       parseCluster,
		}

		parseutil.FindPkgNameRefs(p.Pkg, []pkginfo.QualifiedName{name}, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}
View Source
var KeyspaceParser = &resourceparser.Parser{
	Name: "Cache Keyspace",

	InterestingImports: []paths.Pkg{"encore.dev/storage/cache"},
	Run: func(p *resourceparser.Pass) {
		var (
			names []pkginfo.QualifiedName
			specs = make(map[pkginfo.QualifiedName]*parseutil.ReferenceSpec)
		)
		for _, c := range keyspaceConstructors {
			name := pkginfo.QualifiedName{PkgPath: "encore.dev/storage/cache", Name: c.FuncName}
			names = append(names, name)

			numTypeArgs := 1
			if c.ValueKind != implicitValue {
				numTypeArgs = 2
			}

			c := c
			parseFn := func(d parseutil.ReferenceInfo) {
				parseKeyspace(c, d)
			}

			spec := &parseutil.ReferenceSpec{
				MinTypeArgs: numTypeArgs,
				MaxTypeArgs: numTypeArgs,
				Parse:       parseFn,
			}
			specs[name] = spec
		}

		parseutil.FindPkgNameRefs(p.Pkg, names, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			spec := specs[name]
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}

Functions

func ResolveKeyspaceUsage

func ResolveKeyspaceUsage(data usage.ResolveData, keyspace *Keyspace) usage.Usage

Types

type Cluster

type Cluster struct {
	AST            *ast.CallExpr
	Name           string // The unique name of the cache cluster
	Doc            string // The documentation on the cluster
	EvictionPolicy string
	File           *pkginfo.File
}

func (*Cluster) ASTExpr

func (c *Cluster) ASTExpr() ast.Expr

func (*Cluster) End

func (c *Cluster) End() token.Pos

func (*Cluster) Kind

func (c *Cluster) Kind() resource.Kind

func (*Cluster) Package

func (c *Cluster) Package() *pkginfo.Package

func (*Cluster) Pos

func (c *Cluster) Pos() token.Pos

func (*Cluster) ResourceName

func (c *Cluster) ResourceName() string

func (*Cluster) SortKey added in v1.16.3

func (c *Cluster) SortKey() string

type Keyspace

type Keyspace struct {
	AST     *ast.CallExpr
	Doc     string        // The documentation on the keyspace
	File    *pkginfo.File // File the keyspace is declared in.
	Cluster pkginfo.QualifiedName

	KeyType   schema.Type
	ValueType schema.Type
	Path      *resourcepaths.Path

	// The struct literal for the config. Used to inject additional configuration
	// at compile-time.
	ConfigLiteral *ast.CompositeLit
}

func (*Keyspace) ASTExpr

func (k *Keyspace) ASTExpr() ast.Expr

func (*Keyspace) End

func (k *Keyspace) End() token.Pos

func (*Keyspace) Kind

func (k *Keyspace) Kind() resource.Kind

func (*Keyspace) Package

func (k *Keyspace) Package() *pkginfo.Package

func (*Keyspace) Pos

func (k *Keyspace) Pos() token.Pos

func (*Keyspace) SortKey added in v1.16.3

func (k *Keyspace) SortKey() string

type KeyspaceUsage

type KeyspaceUsage struct {
	usage.Base

	Keyspace *Keyspace
}

Jump to

Keyboard shortcuts

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