Documentation
¶
Index ¶
- Variables
- func Initialize() error
- func InvalidateCache()
- func ResetProvider()
- func SetCacheTTL(ttl time.Duration)
- func SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
- func SetProvider(p CacheProvider) error
- type CacheItem
- type CacheProvider
- type DynamoDBAPI
- type DynamoDBCache
- type MemoryCache
- func (c *MemoryCache) GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool)
- func (c *MemoryCache) Initialize() error
- func (c *MemoryCache) InvalidateCache()
- func (c *MemoryCache) SetCacheTTL(ttl time.Duration)
- func (c *MemoryCache) SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
- type MockCache
- func (c *MockCache) GetCallCounts() (getTree, setTree, invalidate, setTTL, init int)
- func (c *MockCache) GetTree() ([]*models.Node, bool)
- func (c *MockCache) Initialize() error
- func (c *MockCache) InvalidateCache()
- func (c *MockCache) Reset()
- func (c *MockCache) SetCacheTTL(ttl time.Duration)
- func (c *MockCache) SetShouldFail(shouldFail bool)
- func (c *MockCache) SetTree(tree []*models.Node)
- type MockDynamoDBClient
- func (m *MockDynamoDBClient) CreateTable(ctx context.Context, params *dynamodb.CreateTableInput, ...) (*dynamodb.CreateTableOutput, error)
- func (m *MockDynamoDBClient) DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, ...) (*dynamodb.DeleteItemOutput, error)
- func (m *MockDynamoDBClient) DescribeTable(ctx context.Context, params *dynamodb.DescribeTableInput, ...) (*dynamodb.DescribeTableOutput, error)
- func (m *MockDynamoDBClient) GetItem(ctx context.Context, params *dynamodb.GetItemInput, ...) (*dynamodb.GetItemOutput, error)
- func (m *MockDynamoDBClient) PutItem(ctx context.Context, params *dynamodb.PutItemInput, ...) (*dynamodb.PutItemOutput, error)
- type PaginatedTreeResponse
- type RedisCache
- func (c *RedisCache) Close() error
- func (c *RedisCache) GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool)
- func (c *RedisCache) Initialize() error
- func (c *RedisCache) InvalidateCache()
- func (c *RedisCache) SetCacheTTL(ttl time.Duration)
- func (c *RedisCache) SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
Constants ¶
This section is empty.
Variables ¶
var ErrCacheInitialization = errors.New("mock cache initialization failed")
ErrCacheInitialization is returned when the mock cache is configured to fail
Functions ¶
func SetCacheTTL ¶
SetCacheTTL sets the cache time-to-live duration
func SetPaginatedTree ¶
func SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
SetPaginatedTree stores the paginated tree in cache
func SetProvider ¶
func SetProvider(p CacheProvider) error
SetProvider allows changing the cache provider at runtime
Types ¶
type CacheProvider ¶
type CacheProvider interface { // GetPaginatedTree retrieves the paginated tree from cache if available. // Parameters: // - page: The page number // - pageSize: The size of each page // Returns: // - The paginated tree response // - A boolean indicating whether the response was found in cache GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool) // SetPaginatedTree stores the paginated tree in cache. // Parameters: // - page: The page number // - pageSize: The size of each page // - response: The paginated tree response to cache SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse) // InvalidateCache removes all cached data. // This is typically called when the tree structure is modified. InvalidateCache() // SetCacheTTL sets the cache time-to-live duration. // Parameters: // - ttl: The duration after which cached data should expire SetCacheTTL(ttl time.Duration) // Initialize performs any necessary setup for the cache provider. // This may include establishing connections, creating cache instances, // or any other initialization required for the cache to function. // Returns an error if initialization fails. Initialize() error }
CacheProvider defines the interface for cache implementations. It provides methods for caching and retrieving tree structures.
type DynamoDBAPI ¶
type DynamoDBAPI interface { CreateTable(ctx context.Context, params *dynamodb.CreateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error) DescribeTable(ctx context.Context, params *dynamodb.DescribeTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error) GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error) PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error) DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error) }
DynamoDBAPI defines the interface for DynamoDB operations
type DynamoDBCache ¶
type DynamoDBCache struct {
// contains filtered or unexported fields
}
DynamoDBCache implements CacheProvider using DynamoDB
func NewDynamoDBCache ¶
func NewDynamoDBCache() (*DynamoDBCache, error)
NewDynamoDBCache creates a new DynamoDB cache provider
func NewDynamoDBCacheWithClient ¶
func NewDynamoDBCacheWithClient(client DynamoDBAPI) *DynamoDBCache
NewDynamoDBCacheWithClient creates a new DynamoDB cache provider with a custom client
func (*DynamoDBCache) GetTree ¶
func (c *DynamoDBCache) GetTree() ([]*models.Node, bool)
GetTree retrieves the tree from DynamoDB cache if available
func (*DynamoDBCache) Initialize ¶
func (c *DynamoDBCache) Initialize() error
Initialize creates the DynamoDB table if it doesn't exist
func (*DynamoDBCache) InvalidateCache ¶
func (c *DynamoDBCache) InvalidateCache() error
InvalidateCache removes the tree from DynamoDB cache
func (*DynamoDBCache) SetCacheTTL ¶
func (c *DynamoDBCache) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the cache time-to-live duration
func (*DynamoDBCache) SetTree ¶
func (c *DynamoDBCache) SetTree(tree []*models.Node)
SetTree stores the tree in DynamoDB cache
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements CacheProvider using in-memory storage
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
NewMemoryCache creates a new in-memory cache provider
func (*MemoryCache) GetPaginatedTree ¶
func (c *MemoryCache) GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool)
GetPaginatedTree retrieves the paginated tree from cache if available
func (*MemoryCache) Initialize ¶
func (c *MemoryCache) Initialize() error
Initialize performs any necessary setup for the cache provider
func (*MemoryCache) InvalidateCache ¶
func (c *MemoryCache) InvalidateCache()
InvalidateCache removes all cached data
func (*MemoryCache) SetCacheTTL ¶
func (c *MemoryCache) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the cache time-to-live duration
func (*MemoryCache) SetPaginatedTree ¶
func (c *MemoryCache) SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
SetPaginatedTree stores the paginated tree in cache
type MockCache ¶
type MockCache struct { GetTreeCalls int SetTreeCalls int InvalidateCalls int SetTTLCalls int InitCalls int ShouldFail bool // contains filtered or unexported fields }
MockCache is a cache provider that can be used for testing
func (*MockCache) GetCallCounts ¶
GetCallCounts returns the number of times each method was called
func (*MockCache) Initialize ¶
Initialize performs any necessary setup for the cache provider
func (*MockCache) InvalidateCache ¶
func (c *MockCache) InvalidateCache()
InvalidateCache removes the tree from cache
func (*MockCache) SetCacheTTL ¶
SetCacheTTL sets the cache time-to-live duration
func (*MockCache) SetShouldFail ¶
SetShouldFail makes the mock cache fail all operations
type MockDynamoDBClient ¶
type MockDynamoDBClient struct {
// contains filtered or unexported fields
}
MockDynamoDBClient implements DynamoDBAPI for testing
func NewMockDynamoDBClient ¶
func NewMockDynamoDBClient() *MockDynamoDBClient
NewMockDynamoDBClient creates a new mock DynamoDB client
func (*MockDynamoDBClient) CreateTable ¶
func (m *MockDynamoDBClient) CreateTable(ctx context.Context, params *dynamodb.CreateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error)
CreateTable mocks the CreateTable operation
func (*MockDynamoDBClient) DeleteItem ¶
func (m *MockDynamoDBClient) DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)
DeleteItem mocks the DeleteItem operation
func (*MockDynamoDBClient) DescribeTable ¶
func (m *MockDynamoDBClient) DescribeTable(ctx context.Context, params *dynamodb.DescribeTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error)
DescribeTable mocks the DescribeTable operation
func (*MockDynamoDBClient) GetItem ¶
func (m *MockDynamoDBClient) GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)
GetItem mocks the GetItem operation
func (*MockDynamoDBClient) PutItem ¶
func (m *MockDynamoDBClient) PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
PutItem mocks the PutItem operation
type PaginatedTreeResponse ¶
type PaginatedTreeResponse struct { Data []*models.Node `json:"data"` Pagination struct { Page int `json:"page"` PageSize int `json:"pageSize"` Total int64 `json:"total"` TotalPages int64 `json:"totalPages"` HasNext bool `json:"hasNext"` HasPrev bool `json:"hasPrev"` } `json:"pagination"` }
PaginatedTreeResponse represents a paginated tree response
func GetPaginatedTree ¶
func GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool)
GetPaginatedTree retrieves the paginated tree from cache if available
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements CacheProvider using Redis
func NewRedisCache ¶
func NewRedisCache() *RedisCache
NewRedisCache creates a new Redis cache provider
func (*RedisCache) GetPaginatedTree ¶
func (c *RedisCache) GetPaginatedTree(page, pageSize int) (*PaginatedTreeResponse, bool)
GetPaginatedTree retrieves the paginated tree from cache if available
func (*RedisCache) Initialize ¶
func (c *RedisCache) Initialize() error
Initialize performs any necessary setup for the cache provider
func (*RedisCache) InvalidateCache ¶
func (c *RedisCache) InvalidateCache()
InvalidateCache removes all cached data
func (*RedisCache) SetCacheTTL ¶
func (c *RedisCache) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the cache time-to-live duration
func (*RedisCache) SetPaginatedTree ¶
func (c *RedisCache) SetPaginatedTree(page, pageSize int, response *PaginatedTreeResponse)
SetPaginatedTree stores the paginated tree in cache