Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = fmt.Errorf("key not found")
ErrKeyNotFound is returned when a key is not found in the cache.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, value string, ttl time.Duration) error Get(ctx context.Context, key string) (string, error) Del(ctx context.Context, key string) error database.Database }
Cache is a simple key-value store backed by an SQLite database.
func NewCache ¶
NewCache creates a new cache instance with the given name and applies any provided options. The cache is backed by an SQLite database.
The cache is automatically created if it does not exist.
Parameters:
- ctx: the context
- opts: the cache options
Returns:
- cache: the cache instance
- error: an error if the operation failed
Configuration defaults:
- syncInterval: 1 second
- timezone: UTC
Configuration options:
- WithSyncInterval: sets a custom sync interval for the cache.
- WithPath: sets the path to the cache database.
- WithTimezone: sets a custom timezone for the cache.
- WithPurgePercent: sets the percentage of cache entries to purge.
- WithPurgeTimeout: sets the timeout for purging cache entries.
- WithDBOptions: sets the database options.
Example:
cache, err := cache.NewCache(ctx) if err != nil { panic(err) }
type Option ¶
type Option func(*cache)
CacheOption is a function that configures a cache instance.
func WithPath ¶
WithPath sets the path to the cache database. The cache is automatically created if it does not exist.
func WithPurgePercent ¶
WithPurgePercent sets the percentage of cache entries to delete when purging.
func WithPurgeTimeout ¶
WithPurgeTimeout sets the timeout for purging cache entries.
func WithSyncInterval ¶
WithSyncInterval sets a custom sync interval for the cache. The sync interval determines how often the cache is synchronized with the database.
func WithTimezone ¶
WithTimezone sets a custom timezone for the cache.