noop

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package noop is the cache.Cache for a caller who wants no cache at all: every read misses and every write is accepted and forgotten.

The consequence is that the cache is a permanent miss rather than a cold one, so whatever sits behind it must be able to serve every request from its source of truth, at full traffic, forever. Get returns cache.ErrNotFound and GetMany an empty map; the writes report success, because "stored" is a claim about a store the caller already knows is absent.

SetIfPresent is the deliberate exception and returns cache.ErrNotFound, so a component whose correctness rests on a conditional write cannot be handed this cache and appear to work. See that method for the full argument.

cache/config never builds this — a caller who wants it constructs it directly, which keeps "no cache" a decision written in code rather than a configuration fall-through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct{}

Cache is a no-op Cache.

func NewCache

func NewCache[T any]() *Cache[T]

NewCache returns a no-op Cache. It returns the concrete type so a caller who deliberately wants no cache can say so in their own signatures, rather than naming the interface and leaving every reader to wonder which provider is behind it.

func (*Cache[T]) Close

func (c *Cache[T]) Close() error

Close satisfies the interface and releases nothing.

func (*Cache[T]) Delete

func (*Cache[T]) Delete(context.Context, string) error

Delete is a no-op.

func (*Cache[T]) DeleteByPrefix

func (*Cache[T]) DeleteByPrefix(context.Context, string) error

DeleteByPrefix is a no-op.

func (*Cache[T]) DeleteMany

func (*Cache[T]) DeleteMany(context.Context, []string) error

DeleteMany is a no-op.

func (*Cache[T]) Flush

func (*Cache[T]) Flush(context.Context) error

Flush is a no-op.

func (*Cache[T]) Get

func (*Cache[T]) Get(context.Context, string) (*T, error)

Get always returns ErrNotFound.

func (*Cache[T]) GetMany

func (*Cache[T]) GetMany(context.Context, []string) (map[string]*T, error)

GetMany always returns an empty map.

func (*Cache[T]) Ping

func (*Cache[T]) Ping(context.Context) error

Ping is a no-op.

func (*Cache[T]) Set

func (*Cache[T]) Set(context.Context, string, *T, ...cache.WriteOption) error

Set is a no-op.

func (*Cache[T]) SetIfPresent

func (*Cache[T]) SetIfPresent(context.Context, string, *T, ...cache.WriteOption) error

SetIfPresent always returns ErrNotFound.

It is the one write this cache refuses, and refusing is the point. Every other method here can no-op honestly, because "stored" and "deleted" are claims about a store the caller already knows is absent. A conditional write is different: answering nil would assert that the entry existed and was replaced, and a caller that reached for this method did so precisely because it needs that assertion to mean something.

So a component whose correctness rests on a conditional write cannot be silently configured with a noop cache and appear to work. That is the same distinction cache.ErrUnavailable draws for an outage, applied to a store that is absent by configuration rather than by failure.

func (*Cache[T]) SetMany

func (*Cache[T]) SetMany(context.Context, map[string]*T, ...cache.WriteOption) error

SetMany is a no-op.

Jump to

Keyboard shortcuts

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