cache

package
v0.0.0-...-2e9d76f Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	ManifestCache
	// contains filtered or unexported fields
}

Cache contains cached values for a path

func NewCache

func NewCache(fs afero.Fs, os types.Os, path string) *Cache

NewCache loads stored cache values at path

func (*Cache) GetManifestHash

func (c *Cache) GetManifestHash(ctx context.Context, appID string) (Hash, error)

GetManifestHash loads the saved manifest hash from cache

func (*Cache) NewManifestHash

func (c *Cache) NewManifestHash(ctx context.Context, manifest types.AppManifest) (Hash, error)

NewManifestHash creates a hash unique to the manifest

The source of the manifest provided should be noted since values from hooks might not be the same as the API response.

func (*Cache) SetManifestHash

func (c *Cache) SetManifestHash(ctx context.Context, appID string, hash Hash) error

SetManifestHash saves the manifest hash for an app ID

type CacheMock

type CacheMock struct {
	mock.Mock

	ManifestCache
}

func NewCacheMock

func NewCacheMock() *CacheMock

NewCacheMock creates a temporary cache for testing

This mock should overwrite existing caches after setups are performed:

cc := cache.NewCacheMock()
cc.On("GetManifestHash", mock.Anything, mock.Anything).
    Return("placeholder", nil)

proj := config.NewProjectConfigMock()
proj.On("Cache").Return(cc)

clientsMock.Config.ProjectConfig = proj

Mocked arguments can be more specific to mimic unique cache response.

func (*CacheMock) GetManifestHash

func (cm *CacheMock) GetManifestHash(ctx context.Context, appID string) (Hash, error)

func (*CacheMock) NewManifestHash

func (cm *CacheMock) NewManifestHash(ctx context.Context, manifest types.AppManifest) (Hash, error)

func (*CacheMock) SetManifestHash

func (cm *CacheMock) SetManifestHash(ctx context.Context, appID string, hash Hash) error

type Cacher

type Cacher interface {
	ManifestCacher
}

Cacher saves and retrieves specific values

type Hash

type Hash string

Hash is a mapped value for a specific input

func NewHash

func NewHash(bytes []byte) (h Hash)

NewHash creates a hash from provided bytes

Before creating a new hash, provided JSON inputs are standardized with sorted attributes so the same input values are encoded to a matching hash.

Reference: https://stackoverflow.com/questions/18668652/how-to-produce-json-with-sorted-keys-in-go/61887446#61887446

func (Hash) Equals

func (h Hash) Equals(is Hash) bool

Equals returns true if the hash is equal

type ManifestCache

type ManifestCache struct {
	Apps map[string]ManifestCacheApp
}

ManifestCache stores values of an app manifest

type ManifestCacheApp

type ManifestCacheApp struct {
	Hash Hash `json:"hash"` // Hash is a computed value unique to a manifest
}

ManifestCacheApp contains cache details for a specific app manifest

type ManifestCacher

type ManifestCacher interface {
	GetManifestHash(ctx context.Context, appID string) (Hash, error)
	NewManifestHash(ctx context.Context, manifest types.AppManifest) (Hash, error)
	SetManifestHash(ctx context.Context, appID string, hash Hash) error
}

ManifestCacher saves and retrieves specific manifest values

Jump to

Keyboard shortcuts

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