MCPcopy
hub / github.com/go-gorm/gorm / New

Function New

internal/stmt_store/stmt_store.go:99–114  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

97// - A Store instance implemented by lruStore, which internally uses an LRU cache with the specified size,
98// eviction callback, and TTL.
99func 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
116type lruStore struct {
117 lru *lru.LRU[string, *Stmt]

Callers 1

NewPreparedStmtDBFunction · 0.92

Calls 2

NewLRUFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected