Documentation
¶
Index ¶
- Constants
- type Cache
- func (c *Cache) CreatedAt() time.Time
- func (c *Cache) DeletedAt() *time.Time
- func (c *Cache) ExpiresAt() *time.Time
- func (c *Cache) Key() string
- func (c *Cache) SetExpiresAt(t *time.Time)
- func (c *Cache) SetKey(key string)
- func (c *Cache) SetValue(value string)
- func (c *Cache) UpdatedAt() time.Time
- func (c *Cache) Value() string
- type NewStoreOptions
- type StoreInterface
Constants ¶
View Source
const ( COLUMN_ID = "id" COLUMN_KEY = "cache_key" COLUMN_VALUE = "cache_value" COLUMN_EXPIRES_AT = "expires_at" COLUMN_CREATED_AT = "created_at" COLUMN_UPDATED_AT = "updated_at" COLUMN_DELETED_AT = "soft_deleted_at" )
Column names for the cache table
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
orm.ShortID
soft_delete.SoftDeletesMaxDate
KeyField string `db:"cache_key"`
ValueField string `db:"cache_value"`
ExpiresAtField *time.Time `db:"expires_at"`
CreatedAtField time.Time `db:"created_at"`
UpdatedAtField time.Time `db:"updated_at"`
}
Cache type
func (*Cache) SetExpiresAt ¶ added in v1.3.0
SetExpiresAt sets the expiration time
type NewStoreOptions ¶
type NewStoreOptions struct {
DB *sql.DB
CacheTableName string
AutomigrateEnabled bool
DebugEnabled bool
}
NewStoreOptions define the options for creating a new cache store
type StoreInterface ¶
type StoreInterface interface {
// EnableDebug enables or disables debug mode
EnableDebug(debugEnabled bool)
// GetCacheTableName returns the cache table name
GetCacheTableName() string
// SetCacheTableName sets the cache table name
SetCacheTableName(cacheTableName string)
// MigrateDown drops the cache table
MigrateDown(ctx context.Context, tx ...*sql.Tx) error
// MigrateUp creates the cache table
MigrateUp(ctx context.Context, tx ...*sql.Tx) error
// ExpireCacheGoroutine runs the cache expiration goroutine
ExpireCacheGoroutine(ctx context.Context) error
// Set stores a value in the cache
Set(key string, value string, seconds int64) error
// Get retrieves a value from the cache
Get(key string, valueDefault string) (string, error)
// SetJSON stores a JSON value in the cache
SetJSON(key string, value any, seconds int64) error
// GetJSON retrieves a JSON value from the cache
GetJSON(key string, valueDefault any) (any, error)
// Remove removes a value from the cache
Remove(key string) error
// FindByKey finds a cache entry by key
FindByKey(key string) (*Cache, error)
}
StoreInterface defines the interface for a cache store
func NewStore ¶
func NewStore(opts NewStoreOptions) (StoreInterface, error)
NewStore creates a new cache store
Click to show internal directories.
Click to hide internal directories.