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
(size int, ttl time.Duration)
| 97 | // - A Store instance implemented by lruStore, which internally uses an LRU cache with the specified size, |
| 98 | // eviction callback, and TTL. |
| 99 | func New(size int, ttl time.Duration) Store { |
| 100 | if size <= 0 { |
| 101 | size = defaultMaxSize |
| 102 | } |
| 103 | |
| 104 | if ttl <= 0 { |
| 105 | ttl = defaultTTL |
| 106 | } |
| 107 | |
| 108 | onEvicted := func(k string, v *Stmt) { |
| 109 | if v != nil { |
| 110 | go v.Close() |
| 111 | } |
| 112 | } |
| 113 | return &lruStore{lru: lru.NewLRU[string, *Stmt](size, onEvicted, ttl)} |
| 114 | } |
| 115 | |
| 116 | type lruStore struct { |
| 117 | lru *lru.LRU[string, *Stmt] |
no test coverage detected