Documentation
¶
Index ¶
- Constants
- func SetPointedValue(dest interface{}, src interface{})
- func TagsFromContext(ctx context.Context) []string
- func WithInvalidateTags(ctx context.Context, tags ...string) context.Context
- func WithTags(ctx context.Context, tags ...string) context.Context
- type Cacher
- type Caches
- type Config
- type InvalidationEvent
- type MutationType
- type Query
Constants ¶
View Source
const IdentifierPrefix = "gorm-caches::"
Variables ¶
This section is empty.
Functions ¶
func SetPointedValue ¶
func SetPointedValue(dest interface{}, src interface{})
func TagsFromContext ¶
TagsFromContext returns the cache tags stored on ctx by WithTags. Cacher implementations use this in Store to build tag→key index entries.
func WithInvalidateTags ¶
WithInvalidateTags sets tags on the context to indicate which cache entries should be invalidated during a mutation. Use this in your application code before performing CREATE/UPDATE/DELETE operations.
Types ¶
type Cacher ¶
type Cacher interface {
// Get impl should check if a specific key exists in the cache and return its value
// look at Query.Marshal
Get(ctx context.Context, key string, q *Query[any]) (*Query[any], error)
// Store impl should store a cached representation of the val param
// look at Query.Unmarshal
Store(ctx context.Context, key string, val *Query[any]) error
// Invalidate impl should invalidate cached values based on the given event.
// The event contains metadata about the mutation (tables, entity IDs, mutation type, and tags).
// It will be called when INSERT / UPDATE / DELETE queries are sent to the DB.
Invalidate(ctx context.Context, event *InvalidationEvent) error
}
type InvalidationEvent ¶
type InvalidationEvent struct {
Tables []string
EntityIDs []interface{}
MutationType MutationType
Tags []string
}
InvalidationEvent contains metadata about a mutation that triggered cache invalidation.
type MutationType ¶
type MutationType int
MutationType represents the type of mutation that triggered cache invalidation.
const ( MutationCreate MutationType = iota MutationUpdate MutationDelete )
func (MutationType) String ¶
func (m MutationType) String() string
Click to show internal directories.
Click to hide internal directories.