package stmt_store
import "gorm.io/gorm/internal/stmt_store"
Index ¶
Types ¶
type ConnPool ¶
type Stmt ¶
func (*Stmt) Close ¶
func (*Stmt) Error ¶
type Store ¶
type Store interface { // New creates a new Stmt object and caches it. // Parameters: // ctx: The context for the request, which can carry deadlines, cancellation signals, etc. // key: The key representing the SQL query, used for caching and preparing the statement. // isTransaction: Indicates whether this operation is part of a transaction, which may affect the caching strategy. // connPool: A connection pool that provides database connections. // locker: A synchronization lock that is unlocked after initialization to avoid deadlocks. // Returns: // *Stmt: A newly created statement object for executing SQL operations. // error: An error if the statement preparation fails. New(ctx context.Context, key string, isTransaction bool, connPool ConnPool, locker sync.Locker) (*Stmt, error) // Keys returns a slice of all cache keys in the store. Keys() []string // Get retrieves a Stmt object from the store based on the given key. // Parameters: // key: The key used to look up the Stmt object. // Returns: // *Stmt: The found Stmt object, or nil if not found. // bool: Indicates whether the corresponding Stmt object was successfully found. Get(key string) (*Stmt, bool) // Set stores the given Stmt object in the store and associates it with the specified key. // Parameters: // key: The key used to associate the Stmt object. // value: The Stmt object to be stored. Set(key string, value *Stmt) // Delete removes the Stmt object corresponding to the specified key from the store. // Parameters: // key: The key associated with the Stmt object to be deleted. Delete(key string) }
Store defines an interface for managing the caching operations of SQL statements (Stmt). This interface provides methods for creating new statements, retrieving all cache keys, getting cached statements, setting cached statements, and deleting cached statements.
func New ¶
New creates and returns a new Store instance.
Parameters:
- size: The maximum capacity of the cache. If the provided size is less than or equal to 0, it defaults to defaultMaxSize.
- ttl: The time-to-live duration for each cache entry. If the provided ttl is less than or equal to 0, it defaults to defaultTTL.
This function defines an onEvicted callback that is invoked when a cache entry is evicted. The callback ensures that if the evicted value (v) is not nil, its Close method is called asynchronously to release associated resources.
Returns:
- A Store instance implemented by lruStore, which internally uses an LRU cache with the specified size, eviction callback, and TTL.
Source Files ¶
stmt_store.go
- Version
- v1.26.1 (latest)
- Published
- May 7, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 week ago –
Tools for package owners.