cache

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheTypeRedis    CacheType = "redis"
	CacheTypeMemory             = "memory"
	CacheTypeEtcd               = "etcd"
	CacheTypeMemcache           = "memcache"
)

CacheType .

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	GetCache(ctx context.Context, key string) (string, error)
	SetCache(ctx context.Context, key, value string) error
	DeleteCache(ctx context.Context, key string) error
	Close() error
}

Cache defines the interface for cache operations

type CacheManager

type CacheManager struct {
	// contains filtered or unexported fields
}

CacheManager ..

func NewCacheManager

func NewCacheManager(arg *CacheMgrParams) (*CacheManager, error)

NewCacheManager ..

func (*CacheManager) Close

func (cm *CacheManager) Close() error

Close ..

func (*CacheManager) GetCache

func (cm *CacheManager) GetCache() Cache

GetCache ..

func (*CacheManager) Setup

func (cm *CacheManager) Setup(arg *CacheMgrParams) error

Setup initialize the cache

type CacheMgrParams

type CacheMgrParams struct {
	Type          CacheType
	CacheAddrs    string
	CacheUsername string
	CachePassword string
	KeyPrefix     string
	Ttl           time.Duration
	CleanInt      time.Duration
}

CacheMgrParams ..

type CacheType

type CacheType string

type CaptCacheData

type CaptCacheData struct {
	Data   interface{} `json:"data"`
	Type   int         `json:"type"`
	Status int         `json:"status"`
}

CaptCacheData ..

type EtcdClient

type EtcdClient struct {
	// contains filtered or unexported fields
}

EtcdClient implements the Cache interface for etcd

func NewEtcdClient

func NewEtcdClient(addrs, prefix string, ttl time.Duration, username, password string) (*EtcdClient, error)

NewEtcdClient ..

func (*EtcdClient) Close

func (c *EtcdClient) Close() error

Close ..

func (*EtcdClient) DeleteCache

func (c *EtcdClient) DeleteCache(ctx context.Context, key string) error

DeleteCache ..

func (*EtcdClient) GetCache

func (c *EtcdClient) GetCache(ctx context.Context, key string) (string, error)

GetCache retrieves a value from etcd

func (*EtcdClient) SetCache

func (c *EtcdClient) SetCache(ctx context.Context, key, value string) error

SetCache stores a value in etcd

type MemcacheClient

type MemcacheClient struct {
	// contains filtered or unexported fields
}

MemcacheClient implements the Cache interface for Memcached

func NewMemcacheClient

func NewMemcacheClient(addrs, prefix string, ttl time.Duration, username, password string) (*MemcacheClient, error)

NewMemcacheClient ..

func (*MemcacheClient) Close

func (c *MemcacheClient) Close() error

Close ..

func (*MemcacheClient) DeleteCache

func (c *MemcacheClient) DeleteCache(ctx context.Context, key string) error

DeleteCache ..

func (*MemcacheClient) GetCache

func (c *MemcacheClient) GetCache(ctx context.Context, key string) (string, error)

GetCache retrieves a value from Memcached

func (*MemcacheClient) SetCache

func (c *MemcacheClient) SetCache(ctx context.Context, key, value string) error

SetCache stores a value in Memcached

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache is an in-memory cache with TTL and cleanup

func NewMemoryCache

func NewMemoryCache(prefix string, ttl, cleanupInterval time.Duration) *MemoryCache

NewMemoryCache ..

func (*MemoryCache) Close

func (c *MemoryCache) Close() error

Close ..

func (*MemoryCache) DeleteCache

func (c *MemoryCache) DeleteCache(ctx context.Context, key string) error

DeleteCache delete a value in memory cache

func (*MemoryCache) GetCache

func (c *MemoryCache) GetCache(ctx context.Context, key string) (string, error)

GetCache retrieves a value from memory cache

func (*MemoryCache) SetCache

func (c *MemoryCache) SetCache(ctx context.Context, key, value string) error

SetCache stores a value in memory cache

func (*MemoryCache) Stop

func (c *MemoryCache) Stop()

Stop ..

type RedisClient

type RedisClient struct {
	// contains filtered or unexported fields
}

RedisClient implements the Cache interface for Redis

func NewRedisClient

func NewRedisClient(addrs, prefix string, ttl time.Duration, username, password string) (*RedisClient, error)

NewRedisClient ..

func (*RedisClient) Close

func (c *RedisClient) Close() error

Close ..

func (*RedisClient) DeleteCache

func (c *RedisClient) DeleteCache(ctx context.Context, key string) error

DeleteCache delete a value in Redis

func (*RedisClient) GetCache

func (c *RedisClient) GetCache(ctx context.Context, key string) (string, error)

GetCache retrieves a value from Redis

func (*RedisClient) SetCache

func (c *RedisClient) SetCache(ctx context.Context, key, value string) error

SetCache stores a value in Redis

Jump to

Keyboard shortcuts

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