cache

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// GetServerBuild retrieves a server build from cache
	GetServerBuild(filePath string) (reactbuilder.BuildResult, bool, error)
	// SetServerBuild stores a server build in cache
	SetServerBuild(filePath string, build reactbuilder.BuildResult) error
	// RemoveServerBuild removes a server build from cache
	RemoveServerBuild(filePath string) error

	// GetClientBuild retrieves a client build from cache
	GetClientBuild(filePath string) (reactbuilder.BuildResult, bool, error)
	// SetClientBuild stores a client build in cache
	SetClientBuild(filePath string, build reactbuilder.BuildResult) error
	// RemoveClientBuild removes a client build from cache
	RemoveClientBuild(filePath string) error

	// Route mapping
	SetParentFile(routeID, filePath string) error
	GetRouteIDSForParentFile(filePath string) ([]string, error)
	GetAllRouteIDS() ([]string, error)
	GetRouteIDSWithFile(filePath string) ([]string, error)

	// Dependencies
	SetParentFileDependencies(filePath string, dependencies []string) error
	GetParentFilesFromDependency(dependencyPath string) ([]string, error)

	// Clear removes all cached data
	Clear() error
}

Cache defines the interface for build caching

func NewCache

func NewCache(config CacheConfig) (Cache, error)

NewCache creates a cache based on the config

type CacheConfig

type CacheConfig struct {
	Type CacheType // "local" or "redis"

	// Redis options (only used if Type is "redis")
	RedisAddr     string // Redis address (e.g., "localhost:6379")
	RedisPassword string // Redis password
	RedisDB       int    // Redis database number
	RedisTLS      bool   // Enable TLS for Redis connection
}

CacheConfig configures the cache

type CacheType

type CacheType string

CacheType represents the type of cache to use

const (
	CacheTypeLocal CacheType = "local" // In-memory cache (default)
	CacheTypeRedis CacheType = "redis" // Redis distributed cache
)

type LocalCache

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

LocalCache is an in-memory cache implementation It implements the Cache interface

func NewLocalCache

func NewLocalCache() *LocalCache

NewLocalCache creates a new in-memory cache

func NewManager

func NewManager() *LocalCache

NewManager creates a new LocalCache (for backward compatibility)

func (*LocalCache) Clear

func (cm *LocalCache) Clear() error

Clear removes all cached data

func (*LocalCache) GetAllRouteIDS

func (cm *LocalCache) GetAllRouteIDS() ([]string, error)

func (*LocalCache) GetClientBuild

func (cm *LocalCache) GetClientBuild(filePath string) (reactbuilder.BuildResult, bool, error)

func (*LocalCache) GetParentFilesFromDependency

func (cm *LocalCache) GetParentFilesFromDependency(dependencyPath string) ([]string, error)

func (*LocalCache) GetRouteIDSForParentFile

func (cm *LocalCache) GetRouteIDSForParentFile(filePath string) ([]string, error)

func (*LocalCache) GetRouteIDSWithFile

func (cm *LocalCache) GetRouteIDSWithFile(filePath string) ([]string, error)

func (*LocalCache) GetServerBuild

func (cm *LocalCache) GetServerBuild(filePath string) (reactbuilder.BuildResult, bool, error)

func (*LocalCache) RemoveClientBuild

func (cm *LocalCache) RemoveClientBuild(filePath string) error

func (*LocalCache) RemoveServerBuild

func (cm *LocalCache) RemoveServerBuild(filePath string) error

func (*LocalCache) SetClientBuild

func (cm *LocalCache) SetClientBuild(filePath string, build reactbuilder.BuildResult) error

func (*LocalCache) SetParentFile

func (cm *LocalCache) SetParentFile(routeID, filePath string) error

func (*LocalCache) SetParentFileDependencies

func (cm *LocalCache) SetParentFileDependencies(filePath string, dependencies []string) error

func (*LocalCache) SetServerBuild

func (cm *LocalCache) SetServerBuild(filePath string, build reactbuilder.BuildResult) error

type Manager

type Manager = LocalCache

Manager is an alias for LocalCache for backward compatibility

type RedisCache

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

RedisCache provides distributed caching via Redis

func NewRedisCache

func NewRedisCache(config RedisConfig) (*RedisCache, error)

NewRedisCache creates a new Redis cache

func (*RedisCache) Clear

func (rc *RedisCache) Clear() error

Clear removes all gossr keys from cache

func (*RedisCache) Close

func (rc *RedisCache) Close() error

Close closes the Redis connection

func (*RedisCache) GetAllRouteIDS

func (rc *RedisCache) GetAllRouteIDS() ([]string, error)

GetAllRouteIDS returns all route IDs

func (*RedisCache) GetClientBuild

func (rc *RedisCache) GetClientBuild(filePath string) (reactbuilder.BuildResult, bool, error)

GetClientBuild retrieves a client build from Redis

func (*RedisCache) GetParentFilesFromDependency

func (rc *RedisCache) GetParentFilesFromDependency(dependencyPath string) ([]string, error)

GetParentFilesFromDependency returns parent files that depend on a given file using reverse index

func (*RedisCache) GetRouteIDSForParentFile

func (rc *RedisCache) GetRouteIDSForParentFile(filePath string) ([]string, error)

GetRouteIDSForParentFile returns all route IDs for a given file path

func (*RedisCache) GetRouteIDSWithFile

func (rc *RedisCache) GetRouteIDSWithFile(filePath string) ([]string, error)

GetRouteIDSWithFile returns route IDs associated with a file

func (*RedisCache) GetServerBuild

func (rc *RedisCache) GetServerBuild(filePath string) (reactbuilder.BuildResult, bool, error)

GetServerBuild retrieves a server build from Redis

func (*RedisCache) Invalidate

func (rc *RedisCache) Invalidate(filePath string) error

Invalidate removes a specific key from cache

func (*RedisCache) RemoveClientBuild

func (rc *RedisCache) RemoveClientBuild(filePath string) error

RemoveClientBuild removes a client build from Redis

func (*RedisCache) RemoveServerBuild

func (rc *RedisCache) RemoveServerBuild(filePath string) error

RemoveServerBuild removes a server build from Redis

func (*RedisCache) SetClientBuild

func (rc *RedisCache) SetClientBuild(filePath string, build reactbuilder.BuildResult) error

SetClientBuild stores a client build in Redis

func (*RedisCache) SetParentFile

func (rc *RedisCache) SetParentFile(routeID, filePath string) error

SetParentFile maps a routeID to a parent file path

func (*RedisCache) SetParentFileDependencies

func (rc *RedisCache) SetParentFileDependencies(filePath string, dependencies []string) error

SetParentFileDependencies sets dependencies for a parent file with reverse index

func (*RedisCache) SetServerBuild

func (rc *RedisCache) SetServerBuild(filePath string, build reactbuilder.BuildResult) error

SetServerBuild stores a server build in Redis

func (*RedisCache) Stats

func (rc *RedisCache) Stats(ctx context.Context) (map[string]interface{}, error)

Stats returns cache statistics

type RedisConfig

type RedisConfig struct {
	Addr     string        // Redis address (e.g., "localhost:6379")
	Password string        // Redis password (empty for no auth)
	DB       int           // Redis database number
	TTL      time.Duration // Cache TTL (0 = no expiration)
	Prefix   string        // Key prefix (default: "gossr:")
	UseTLS   bool          // Enable TLS connection
}

RedisConfig configures the Redis cache

Jump to

Keyboard shortcuts

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