mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
fb6a3edb89
- Physically purged all legacy internal/ packages, centralized pkg/model/ and pkg/repository/ - Migrated domain models and database repositories into self-contained owner plugins (user, auth, message_gateway, admin, upload, risk_control) - Decoupled cross-plugin interactions via pure core/contracts and typed EventBus - Ensured 100% test coverage pass, zero data races (-race clean), and 0 lint issues in make code-check
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package contracts defines unified service interfaces and DTOs for cross-plugin communication.
|
|
package contracts
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// ErrCacheMiss is returned when an item is not found in the cache.
|
|
var ErrCacheMiss = errors.New("contracts/cache: key not found")
|
|
|
|
// CacheService defines the contract for multi-layer cache operations (RAM L1 + Redis L2 + Pub/Sub invalidation).
|
|
type CacheService interface {
|
|
// Get retrieves an item from cache into target. Returns ErrCacheMiss if not found.
|
|
Get(ctx context.Context, key string, target any) error
|
|
|
|
// Set stores an item into cache with a specified time-to-live duration.
|
|
Set(ctx context.Context, key string, value any, ttl time.Duration) error
|
|
|
|
// Delete evicts a key from local and remote cache tiers and broadcasts invalidation.
|
|
Delete(ctx context.Context, key string) error
|
|
|
|
// GetOrSet retrieves an item from cache, or calls loader to populate and return if missing.
|
|
GetOrSet(ctx context.Context, key string, target any, ttl time.Duration, loader func() (any, error)) error
|
|
|
|
// Invalidate is a semantic alias for Delete.
|
|
Invalidate(ctx context.Context, key string) error
|
|
}
|