cache

package
v0.0.0-...-5298318 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheService

type CacheService interface {
	GetPredictions(ctx context.Context, stationID string, date time.Time) (*models.TidePredictionRecord, error)
	SavePredictionsBatch(ctx context.Context, records []models.TidePredictionRecord) error
}

type DynamoDBClient

DynamoDBClient interface defines the DynamoDB operations we use

func NewDynamoClient

func NewDynamoClient(ctx context.Context) (DynamoDBClient, error)

NewDynamoClient creates a new DynamoDB client based on environment

type DynamoPredictionCache

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

DynamoPredictionCache handles caching tide predictions in DynamoDB

func NewDynamoPredictionCache

func NewDynamoPredictionCache(client DynamoDBClient, cacheConfig *config.CacheConfig) *DynamoPredictionCache

func (*DynamoPredictionCache) GetPredictions

func (c *DynamoPredictionCache) GetPredictions(ctx context.Context, stationID string, date time.Time) (*models.TidePredictionRecord, error)

GetPredictions retrieves cached predictions for a station and date

func (*DynamoPredictionCache) SavePredictions

func (c *DynamoPredictionCache) SavePredictions(ctx context.Context, record models.TidePredictionRecord) error

SavePredictions saves predictions to the cache

func (*DynamoPredictionCache) SavePredictionsBatch

func (c *DynamoPredictionCache) SavePredictionsBatch(ctx context.Context, records []models.TidePredictionRecord) error

SavePredictionsBatch saves multiple prediction records to the cache

type GraphQLCache

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

func NewGraphQLCache

func NewGraphQLCache(cfg *config.CacheConfig) (*GraphQLCache, error)

func (*GraphQLCache) Add

func (c *GraphQLCache) Add(_ context.Context, key string, value interface{})

func (*GraphQLCache) Clear

func (c *GraphQLCache) Clear()

func (*GraphQLCache) Get

func (c *GraphQLCache) Get(_ context.Context, key string) (interface{}, bool)

type GraphQLCacheEntry

type GraphQLCacheEntry struct {
	Data      string // Store the actual query string
	ExpiresAt time.Time
}

type LRUCacheEntry

type LRUCacheEntry struct {
	Data      *models.TidePredictionRecord
	ExpiresAt time.Time
}

LRUCacheEntry wraps the cached data with metadata

type LRUCacheService

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

LRUCacheService provides a two-layer caching system using LRU and DynamoDB

func NewCacheService

func NewCacheService(ctx context.Context, config *config.CacheConfig) (*LRUCacheService, error)

NewCacheService creates a new cache service with both LRU and DynamoDB caching

func (*LRUCacheService) Clear

func (c *LRUCacheService) Clear()

Clear removes all entries from the LRU cache

func (*LRUCacheService) GetCacheStats

func (c *LRUCacheService) GetCacheStats() map[string]uint64

GetCacheStats returns statistics about cache hits and misses

func (*LRUCacheService) GetPredictions

func (c *LRUCacheService) GetPredictions(ctx context.Context, stationID string, date time.Time) (*models.TidePredictionRecord, error)

GetPredictions tries to get predictions first from LRU cache, then from DynamoDB

func (*LRUCacheService) SavePredictions

func (c *LRUCacheService) SavePredictions(ctx context.Context, record models.TidePredictionRecord) error

SavePredictions saves predictions to both LRU and DynamoDB caches

func (*LRUCacheService) SavePredictionsBatch

func (c *LRUCacheService) SavePredictionsBatch(ctx context.Context, records []models.TidePredictionRecord) error

SavePredictionsBatch saves multiple predictions to both caches

type S3Client

type S3Client interface {
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
}

S3Client defines the interface for S3 operations we need

type S3StationCache

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

S3StationCache provides caching for station lists in S3

func (*S3StationCache) GetStations

func (c *S3StationCache) GetStations(ctx context.Context) ([]models.Station, error)

GetStations retrieves stations from S3 cache if available and valid

func (*S3StationCache) SaveStations

func (c *S3StationCache) SaveStations(ctx context.Context, stations []models.Station) error

SaveStations saves stations to S3 cache

type StationCache

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

func NewStationCache

func NewStationCache(cacheConfig *config.CacheConfig) *StationCache

func (*StationCache) GetStations

func (c *StationCache) GetStations() []models.Station

func (*StationCache) SetStations

func (c *StationCache) SetStations(stations []models.Station)

type StationListCacheProvider

type StationListCacheProvider interface {
	GetStations(ctx context.Context) ([]models.Station, error)
	SaveStations(ctx context.Context, stations []models.Station) error
}

StationListCacheProvider defines interface for station list caching

type StationListCacheRecord

type StationListCacheRecord struct {
	Stations    []models.Station `json:"stations"`
	LastUpdated int64            `json:"lastUpdated"`
	TTL         int64            `json:"ttl"`
}

StationListCacheRecord represents the cached station list with metadata

Jump to

Keyboard shortcuts

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