cache

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCacheCommands

func AddCacheCommands(rootCmd *cobra.Command, manager *Manager)

AddCacheCommands adds cache-related commands to the root command

Types

type CacheConfig

type CacheConfig struct {
	MaxSize    int64         // Maximum size in bytes
	MaxEntries int           // Maximum number of entries
	TTL        time.Duration // Time-to-live for cache entries
}

CacheConfig holds configuration for the cache manager

type CacheInfo

type CacheInfo struct {
	Key  string `json:"key"`
	Size int    `json:"size"`
}

CacheInfo represents information about a cached item

type CachedResponse

type CachedResponse struct {
	StatusCode int                 `json:"status_code"`
	Body       []byte              `json:"body"`
	Headers    map[string][]string `json:"headers"`
	CachedAt   time.Time           `json:"cached_at"`
	ExpiresAt  time.Time           `json:"expires_at"`
}

CachedResponse represents a cached HTTP response

type Manager

type Manager struct {
	OfflineConfig *OfflineConfig
	// contains filtered or unexported fields
}

Manager handles caching operations

func NewManager

func NewManager(config CacheConfig) (*Manager, error)

NewManager creates a new cache manager with configuration

func (*Manager) BatchGet

func (m *Manager) BatchGet(keys []string) map[string]*CachedResponse

BatchGet retrieves multiple cached responses efficiently

func (*Manager) ClearCache

func (m *Manager) ClearCache() error

ClearCache clears all cached items

func (*Manager) GenerateCacheKey

func (m *Manager) GenerateCacheKey(method, endpoint string) string

GenerateCacheKey creates a unique key for caching

func (*Manager) Get

func (m *Manager) Get(key string) (*CachedResponse, bool, error)

Get retrieves a cached response with LRU update

func (*Manager) ListCache

func (m *Manager) ListCache() ([]CacheInfo, error)

ListCache returns information about all cached items

func (*Manager) Remove

func (m *Manager) Remove(key string) error

Remove removes a cache entry

func (*Manager) Set

func (m *Manager) Set(key string, statusCode int, body []byte, headers map[string][]string) error

Set stores a response in cache with size management

type OfflineConfig

type OfflineConfig struct {
	Mode              OfflineMode   `json:"mode"`
	LastOnlineCheck   time.Time     `json:"last_online_check"`
	NetworkTimeout    time.Duration `json:"network_timeout"`
	AutoSyncInterval  time.Duration `json:"auto_sync_interval"`
	PendingOperations []Operation   `json:"pending_operations"`
	// contains filtered or unexported fields
}

OfflineConfig stores offline operation settings

func (*OfflineConfig) ClearPendingOperations

func (c *OfflineConfig) ClearPendingOperations()

ClearPendingOperations removes all queued operations

func (*OfflineConfig) GetPendingOperations

func (c *OfflineConfig) GetPendingOperations() []Operation

GetPendingOperations returns all queued operations

func (*OfflineConfig) IsOnline

func (c *OfflineConfig) IsOnline() bool

IsOnline checks if network connectivity is available

func (*OfflineConfig) QueueOperation

func (c *OfflineConfig) QueueOperation(method, endpoint string, payload []byte)

QueueOperation adds an operation to be executed when online

func (*OfflineConfig) SyncPendingOperations

func (c *OfflineConfig) SyncPendingOperations(client *http.Client) error

SyncPendingOperations attempts to execute queued operations

type OfflineMode

type OfflineMode int

OfflineMode represents the offline operation mode

const (
	// OnlineMode normal operation with network access
	OnlineMode OfflineMode = iota
	// AutoOfflineMode automatically switches to offline mode when network is unavailable
	AutoOfflineMode
	// StrictOfflineMode forces offline-only operation
	StrictOfflineMode
)

type Operation

type Operation struct {
	Method    string          `json:"method"`
	Endpoint  string          `json:"endpoint"`
	Payload   json.RawMessage `json:"payload,omitempty"`
	CreatedAt time.Time       `json:"created_at"`
}

Operation represents a pending operation to be synced

Jump to

Keyboard shortcuts

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