Documentation
¶
Index ¶
Constants ¶
const Version = "v1.0.4"
Version is the current version of the distributed-cache library.
Variables ¶
var ErrCacheClosed = errors.New("cache is closed")
ErrCacheClosed is returned when operations are performed on a closed cache.
var ErrDeserializationFailed = errors.New("deserialization failed")
ErrDeserializationFailed is returned when deserialization fails.
var ErrInvalidConfig = errors.New("invalid cache configuration")
ErrInvalidConfig is returned when the cache configuration is invalid.
var ErrNotFound = errors.New("key not found")
ErrNotFound is returned when a key is not found in the cache.
var ErrPubSubFailed = errors.New("pub/sub operation failed")
ErrPubSubFailed is returned when pub/sub operations fail.
var ErrRedisConnection = errors.New("redis connection failed")
ErrRedisConnection is returned when Redis connection fails.
var ErrSerializationFailed = errors.New("serialization failed")
ErrSerializationFailed is returned when serialization fails.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// PodID is the unique identifier for this pod/instance.
// Used to avoid self-invalidation in pub/sub.
PodID string
// LocalCacheConfig configures the local cache.
LocalCacheConfig LocalCacheConfig
// LocalCacheFactory is the factory for creating local cache instances.
// If nil, defaults to Ristretto factory.
LocalCacheFactory LocalCacheFactory
// RedisAddr is the Redis server address (e.g., "localhost:6379").
RedisAddr string
// RedisPassword is the optional Redis password.
RedisPassword string
// RedisDB is the Redis database number.
RedisDB int
// InvalidationChannel is the Redis pub/sub channel for cache invalidation.
InvalidationChannel string
// SerializationFormat specifies how values are serialized ("json" or "msgpack").
SerializationFormat string
// Marshaller is the marshaller for serialization.
// If nil, defaults to JSON marshaller.
Marshaller Marshaller
// Logger is the logger for debug logging.
// If nil, defaults to no-op logger.
Logger Logger
// DebugMode enables debug logging.
DebugMode bool
// ContextTimeout is the default timeout for cache operations.
ContextTimeout time.Duration
// EnableMetrics enables metrics collection.
EnableMetrics bool
// OnError is called when an error occurs in background operations.
OnError func(error)
// ReaderCanSetToRedis controls whether reader nodes are allowed to write data to Redis.
// When false (default), reader nodes will only update local cache but NOT write to Redis.
ReaderCanSetToRedis bool
// OnSetLocalCache is a callback for custom processing of data before storing in local cache.
// This callback is invoked when an invalidation event with action "set" is received.
// When nil (default), the default behavior is used: unmarshal the value and store in local cache.
OnSetLocalCache func(event InvalidationEvent) any
}
Config configures a distributed cache instance.
type InvalidationEvent ¶
type InvalidationEvent = cache.InvalidationEvent
InvalidationEvent is an alias for cache.InvalidationEvent.
type LocalCacheConfig ¶
type LocalCacheConfig = cache.LocalCacheConfig
LocalCacheConfig is an alias for cache.LocalCacheConfig.
func DefaultLocalCacheConfig ¶
func DefaultLocalCacheConfig() LocalCacheConfig
DefaultLocalCacheConfig returns default local cache configuration for Ristretto.
type LocalCacheFactory ¶
type LocalCacheFactory = cache.LocalCacheFactory
LocalCacheFactory is an alias for cache.LocalCacheFactory.
type LocalCacheMetrics ¶
type LocalCacheMetrics = cache.LocalCacheMetrics
LocalCacheMetrics is an alias for cache.LocalCacheMetrics.
type VersionInfo ¶
VersionInfo provides version information.
func GetVersionInfo ¶
func GetVersionInfo() VersionInfo
GetVersionInfo returns the current version information.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
comparison
command
|
|
|
custom-config
command
|
|
|
custom-local-cache
command
|
|
|
custom-logger
command
|
|
|
custom-marshaller
command
|
|
|
debug-mode
command
|
|
|
kubernetes
command
|
|
|
lfu
command
|
|
|
lru
command
|
|
|
stale-data-prevention
command
Package main demonstrates improved stale data prevention with proper test scenarios that actually validate version conflicts and cache-aside pattern issues.
|
Package main demonstrates improved stale data prevention with proper test scenarios that actually validate version conflicts and cache-aside pattern issues. |