From 2ec55b55c44e38af737931d2f5a2b994c8d1a629 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 25 Apr 2025 11:33:15 +0800 Subject: [PATCH] Rename lru store --- internal/stmt_store/stmt_store.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/stmt_store/stmt_store.go b/internal/stmt_store/stmt_store.go index 606ff761..56c19999 100644 --- a/internal/stmt_store/stmt_store.go +++ b/internal/stmt_store/stmt_store.go @@ -37,10 +37,6 @@ type Store interface { Delete(key string) } -type LRUStore struct { - lru *lru.LRU[string, *Stmt] -} - const ( defaultMaxSize = (1 << 63) - 1 defaultTTL = time.Hour * 24 @@ -60,14 +56,18 @@ func New(size int, ttl time.Duration) Store { go v.Close() } } - return &LRUStore{lru: lru.NewLRU[string, *Stmt](size, onEvicted, ttl)} + return &lruStore{lru: lru.NewLRU[string, *Stmt](size, onEvicted, ttl)} } -func (s *LRUStore) Keys() []string { +type lruStore struct { + lru *lru.LRU[string, *Stmt] +} + +func (s *lruStore) Keys() []string { return s.lru.Keys() } -func (s *LRUStore) Get(key string) (*Stmt, bool) { +func (s *lruStore) Get(key string) (*Stmt, bool) { stmt, ok := s.lru.Get(key) if ok && stmt != nil { <-stmt.prepared @@ -75,11 +75,11 @@ func (s *LRUStore) Get(key string) (*Stmt, bool) { return stmt, ok } -func (s *LRUStore) Set(key string, value *Stmt) { +func (s *lruStore) Set(key string, value *Stmt) { s.lru.Add(key, value) } -func (s *LRUStore) Delete(key string) { +func (s *lruStore) Delete(key string) { s.lru.Remove(key) } @@ -87,7 +87,7 @@ type ConnPool interface { PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) } -func (s *LRUStore) New(ctx context.Context, key string, isTransaction bool, conn ConnPool, locker sync.Locker) (_ *Stmt, err error) { +func (s *lruStore) New(ctx context.Context, key string, isTransaction bool, conn ConnPool, locker sync.Locker) (_ *Stmt, err error) { cacheStmt := &Stmt{ Transaction: isTransaction, prepared: make(chan struct{}),