Documentation
¶
Index ¶
- Variables
- func CheckQueryMatch(model interface{}, tableName string, columnToFieldMap map[string]string, ...) (bool, error)
- func ParseExactMatchFields(params types.QueryParams) map[string][]interface{}
- func ResetGlobalCacheIndex()
- type CacheIndex
- func (idx *CacheIndex) GetFullTableCountKeys(tableName string) []string
- func (idx *CacheIndex) GetFullTableListKeys(tableName string) []string
- func (idx *CacheIndex) GetKeysByValue(table, field string, value interface{}) []string
- func (idx *CacheIndex) GetQueryParamsForKey(cacheKey string) (types.QueryParams, bool)
- func (idx *CacheIndex) RegisterQuery(tableName, cacheKey string, params types.QueryParams)
- type CacheKeyLockManagerInternal
Constants ¶
This section is empty.
Variables ¶
var GlobalCacheIndex = NewCacheIndex()
Global instance of the cache index. This should be initialized once, potentially during application startup.
var GlobalCacheKeyLocker = NewCacheKeyLockManagerInternal()
GlobalCacheKeyLocker provides a global instance of the lock manager for cache keys.
Functions ¶
func CheckQueryMatch ¶
func CheckQueryMatch(model interface{}, tableName string, columnToFieldMap map[string]string, params types.QueryParams) (bool, error)
CheckQueryMatch evaluates if a given model instance satisfies the WHERE clause defined in the provided QueryParams. It now takes the model as interface{} and requires ModelInfo to be passed in.
Supports =, LIKE, >, <, >=, <=, IN, !=, <>, NOT LIKE, NOT IN operators joined by AND. Support for OR clauses or complex LIKE patterns is NOT yet implemented.
func ParseExactMatchFields ¶
func ParseExactMatchFields(params types.QueryParams) map[string][]interface{}
ParseExactMatchFields parses QueryParams and returns a map of field name to value slice for all exact match (=, IN) conditions. Only supports simple conditions connected by AND.
func ResetGlobalCacheIndex ¶
func ResetGlobalCacheIndex()
ResetGlobalCacheIndex resets the global cache index to a new empty state. Primarily useful for testing purposes to ensure test isolation.
Types ¶
type CacheIndex ¶
type CacheIndex struct {
// FieldIndex maps table -> field -> set of cache keys (for fallback, e.g. range queries)
// Example: FieldIndex["users"]["age"] = {"list:users:hash2": true, ...}
FieldIndex map[string]map[string]map[string]bool
// TableToFullTableListKeys records all list cache keys with empty where clause (i.e., full table cache)
TableToFullTableListKeys map[string]map[string]bool
// contains filtered or unexported fields
}
CacheIndex tracks which query cache keys might be affected by changes to a specific table. It maintains a map from table names to a set of cache keys, and a map from cache keys back to their corresponding QueryParams. EXPORTED
func NewCacheIndex ¶
func NewCacheIndex() *CacheIndex
NewCacheIndex creates and initializes a new CacheIndex.
func (*CacheIndex) GetFullTableCountKeys ¶ added in v0.1.14
func (idx *CacheIndex) GetFullTableCountKeys(tableName string) []string
GetFullTableCountKeys returns all count cache keys for the table with empty where clause (i.e., full table count cache)
func (*CacheIndex) GetFullTableListKeys ¶
func (idx *CacheIndex) GetFullTableListKeys(tableName string) []string
GetFullTableListKeys returns all list cache keys for the table with empty where clause (i.e., full table cache)
func (*CacheIndex) GetKeysByValue ¶
func (idx *CacheIndex) GetKeysByValue(table, field string, value interface{}) []string
GetKeysByValue returns all cache keys registered for a given table, field, and value (as interface{}). If no keys are found, returns an empty slice.
func (*CacheIndex) GetQueryParamsForKey ¶
func (idx *CacheIndex) GetQueryParamsForKey(cacheKey string) (types.QueryParams, bool)
GetQueryParamsForKey returns the QueryParams associated with a given cache key. It returns the QueryParams and true if the key was found, otherwise zero QueryParams and false. It is safe for concurrent use.
func (*CacheIndex) RegisterQuery ¶
func (idx *CacheIndex) RegisterQuery(tableName, cacheKey string, params types.QueryParams)
RegisterQuery registers a query cache key (and its associated QueryParams) as being associated with a specific table. This should be called when a query result (list or count) is cached. It is safe for concurrent use.
type CacheKeyLockManagerInternal ¶
type CacheKeyLockManagerInternal struct {
// contains filtered or unexported fields
}
CacheKeyLockManagerInternal manages a map of mutexes, one for each cache key. It uses sync.Map for efficient concurrent access.
func NewCacheKeyLockManagerInternal ¶
func NewCacheKeyLockManagerInternal() *CacheKeyLockManagerInternal
NewCacheKeyLockManagerInternal creates a new lock manager.
func (*CacheKeyLockManagerInternal) Lock ¶
func (m *CacheKeyLockManagerInternal) Lock(key string)
Lock acquires the mutex associated with the given cache key. If the mutex does not exist, it is created. This operation blocks until the lock is acquired.
func (*CacheKeyLockManagerInternal) Unlock ¶
func (m *CacheKeyLockManagerInternal) Unlock(key string)
Unlock releases the mutex associated with the given cache key. It is crucial to call Unlock after the critical section protected by Lock. Typically used with defer: `defer cacheKeyLocker.Unlock(key)`.