cache

package
v0.0.0-...-c436d6b Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 4 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[T Element] struct {
	// contains filtered or unexported fields
}

Cache provides caching of containers or photos within a container so we do not need to do a HTTP request to lookup info every time we want info on an element.

func NewCache

func NewCache[T Element](elementPageFunc elementPageFunc[T]) *Cache[T]

func (*Cache[T]) Add

func (c *Cache[T]) Add(e T)

Add may be called to add a element to the cache. This can be useful when a element is created

func (*Cache[T]) AddDeletedListener

func (c *Cache[T]) AddDeletedListener(l ElementDeletedListener)

func (*Cache[T]) All

func (c *Cache[T]) All(ctx context.Context) ([]T, error)

All will return all elements

If all elements for this container are already in the cache then it will return directly from the cache. If not all elements are known then it will build the cache by asking for pages until it discovers a page that has no elements and then returns all elements in the cache.

func (*Cache[T]) ElementCount

func (c *Cache[T]) ElementCount(ctx context.Context) (int64, error)

ElementCount will return the number of elements

func (*Cache[T]) ElementDeleted

func (c *Cache[T]) ElementDeleted(ctx context.Context, e Element) (err error)

func (*Cache[T]) ElementWithID

func (c *Cache[T]) ElementWithID(ctx context.Context, id types.ID) (T, error)

get the element with the specified ID. In the event that there is no element with the specified ID a nil Photo is returned

func (*Cache[T]) ElementWithUniqueName

func (c *Cache[T]) ElementWithUniqueName(ctx context.Context, name string) (T, error)

func (*Cache[T]) ElementsWithName

func (c *Cache[T]) ElementsWithName(ctx context.Context, name string) ([]T, error)

get elements with a specific name. In the event that there are no elements with the specified name nil is returned

func (*Cache[T]) Remove

func (c *Cache[T]) Remove(ctx context.Context, e T) (err error)

func (*Cache[T]) Reset

func (c *Cache[T]) Reset()

Reset should be called in situations where the cache may no longer be valid any more to reset all cache state

type Element

type Element interface {
	ID() types.ID
	Name(ctx context.Context) (string, error)
}

type ElementDeletedListener

type ElementDeletedListener interface {
	ElementDeleted(ctx context.Context, e Element) error
}

type ElementUniqueNameGenerator

type ElementUniqueNameGenerator interface {
	Element

	// GenerateUniqueName generates a unique name, it does not need to check if
	// any other element share the same "normal" name before generating the
	// unique version of it's name
	GenerateUniqueName(ctx context.Context) (string, error)
}

type ListenableElement

type ListenableElement interface {
	Element
	AddDeletedListener(l ElementDeletedListener)
}

Jump to

Keyboard shortcuts

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